Jump to content

Archived

This topic is now archived and is closed to further replies.

zirgs

what is wrong?

Recommended Posts

Hi there can anyoneplease chek my code and say why php is displaying this error
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected '{', expecting '(' in G:\www\Apache2\public\admin\add.php on line 14[/quote]
Code:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php

$db_username = "*****";
$db_pasword = "*****";
$db_host = "******";
$db = "news";
@mysql_connect($db_host, $db_username, $db_pasword) or die("Can't connect to database!");
@mysql_select_db($db) or die("Can't select database!");

if ( $_POST[title] == "" || $_POST[date] == "" )
{
echo "Some fields were left blank!";
}
elseif { $_POST[new] == "" }
{
echo "You didn't entered the new!";
}
else
{
$query="INSERT INTO news (title,date,new,short_news) VALUES ('$_POST[title]','$_POST[date]','$_POST[new]','$_POST[short_new]')";
if(!mysql_db_query($db,$query)) die(mysql_error());
echo "News added succesfully!";
}

?>
[/quote]
thanks!

Share this post


Link to post
Share on other sites
elseif { $_POST[new] == "" }

You're using {} instead of ().

Share this post


Link to post
Share on other sites
oh ... [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] ... dumb ass me ... but now i'm getting this error
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Parse error: parse error, unexpected T_ECHO in G:\www\Apache2\public\admin\add.php on line 12[/quote]
no sense to me what is t_echo ... ? any help another time?

Share this post


Link to post
Share on other sites
$_POST[title]

should be:
$_POST['title']

And the same with the rest of them. You need quotes.

Share this post


Link to post
Share on other sites
i thought that it's not obligatory... but it's something in this line i think because it's 12 line
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]echo "Some fields were left blank!";[/quote]
sorry for so much questions but i really want to figure it out :)

Share this post


Link to post
Share on other sites
You're getting the error on that line because it expects something else to be closed before that.

Post your most recent code again.

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] <?php

$db_username = "*****";
$db_pasword = "*****";
$db_host = "******";
$db = "news";
@mysql_connect($db_host, $db_username, $db_pasword) or die("Can't connect to database!");
@mysql_select_db($db) or die("Can't select database!");

if ( $_POST['title'] == "" || $_POST['date'] == "" )
(
echo "Some fields were left blank!";
)
elseif ( $_POST['new'] == "" )
(
echo "You didn't entered the new!";
)
else
(
$query="INSERT INTO news (title,date,new,short_news) VALUES ('$_POST['title']','$_POST['date']','$_POST['new']','$_POST['short_new']')";
if(!mysql_db_query($db,$query)) die(mysql_error());
echo "News added succesfully!";
)

?>[/quote]

Share this post


Link to post
Share on other sites
Whoa whoa whoa... change it to this:
[code]
if ( $_POST['title'] == "" || $_POST['date'] == "" )
{
echo "Some fields were left blank!";
}
elseif ( $_POST['new'] == "" )
{
echo "You didn't entered the new!";
}
else
{
$query="INSERT INTO news (title,date,new,short_news) VALUES ('$_POST['title']','$_POST['date']','$_POST['new']','$_POST['short_new']')";
if(!mysql_db_query($db,$query)) die(mysql_error());
echo "News added succesfully!";
}

?>[/code]

Parenthesis around the evaluation statement, brackets around the if contents.

Share this post


Link to post
Share on other sites
thanks for the advices i've just realised that it was strupid to first do connection to database and then check for empty fields ... i've made first check and then connection and query ... and no errors [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]
cheers!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.