Jump to content


Photo

what is wrong?


  • Please log in to reply
8 replies to this topic

#1 zirgs

zirgs
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 June 2006 - 02:55 PM

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!

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 02:56 PM

elseif { $_POST[new] == "" }

You're using {} instead of ().

Info: PHP Manual


#3 zirgs

zirgs
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 June 2006 - 04:39 PM

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?

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 05:07 PM

$_POST[title]

should be:
$_POST['title']

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

Info: PHP Manual


#5 zirgs

zirgs
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 June 2006 - 05:48 PM

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 :)

#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 05:52 PM

You're getting the error on that line because it expects something else to be closed before that.

Post your most recent code again.

Info: PHP Manual


#7 zirgs

zirgs
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 June 2006 - 06:10 PM

[!--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]

#8 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 06:12 PM

Whoa whoa whoa... change it to this:
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!";
}

?>

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

Info: PHP Manual


#9 zirgs

zirgs
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 07 June 2006 - 06:46 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users