zirgs Posted June 6, 2006 Share Posted June 6, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/ Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 elseif { $_POST[new] == "" }You're using {} instead of (). Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/#findComment-42438 Share on other sites More sharing options...
zirgs Posted June 6, 2006 Author Share Posted June 6, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/#findComment-42468 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 $_POST[title]should be:$_POST['title']And the same with the rest of them. You need quotes. Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/#findComment-42477 Share on other sites More sharing options...
zirgs Posted June 6, 2006 Author Share Posted June 6, 2006 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/#findComment-42503 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 You're getting the error on that line because it expects something else to be closed before that.Post your most recent code again. Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/#findComment-42507 Share on other sites More sharing options...
zirgs Posted June 6, 2006 Author Share Posted June 6, 2006 [!--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] Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/#findComment-42516 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/#findComment-42517 Share on other sites More sharing options...
zirgs Posted June 7, 2006 Author Share Posted June 7, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/11332-what-is-wrong/#findComment-42692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.