crystalnano Posted June 13, 2009 Share Posted June 13, 2009 i have a edit news code but i cannot edit code it says Parse error: syntax error, unexpected '{', expecting '(' in N:\news\prev2~.php on line 57 here is code <title>Edit News</title> <?php //LAST UPDATE // 27-09-2007 include("config.php"); $error = ""; $error1 = ""; $error2 = ""; $error3 = ""; $error4 = ""; $error5 = ""; $newsid = $_GET['newsid']; if(isset($_POST['submit'])) { $title = $_POST['title']; $text1 = $_POST['text1']; $text2 = $_POST['text2']; //check if (title) field is empty then print error message. if(!$title){ //this means If the title is really empty. $error = "Error: News title is a required field. Please fill it."; }// end of if elseif ((bool) preg_match('/[0-9]/', $title)) { $error3 = "Error: News title must not contain numbers. Please refill it, with all numbers removed."; } elseif(!$text1){ //this means If the title is really empty. $error1= "Error: News text1 is a required field. Please fill it."; } elseif ((bool) preg_match('/[0-9]/', $text1)) { $error4 = "Error: News title must not contain numbers. Please refill it, with all numbers removed."; } elseif(!$text2){ //this means If the title is really empty. $error2= "Error: News text2 is a required field. Please fill it."; } elseif ((bool) preg_match('/[0-9]/', $text2)) { $error5 = "Error: News title must not contain numbers. Please refill it with all numbers removed."; } elseif{$result = mysql_query"UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect");} } echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=index.php>"; $done="TRUE"; } if ($done !="TRUE") else($newsid) { $result = mysql_query("SELECT * FROM news WHERE newsid='$newsid' ",$connect); while($myrow = mysql_fetch_assoc($result)) { $title = $myrow["title"]; $text1 = $myrow["text1"]; } $text2= $myrow["text2"]; ?> <br> <h3>::Edit News</h3> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="newsid" value="<? echo $myrow['newsid']?>"> Title: <input name="title" size="40" maxlength="255" value="<? echo $title; ?>"><?php echo $error ?> <?php echo $error3 ?> <br> Text1: <textarea name="text1" rows="7" cols="30"><? echo $text1; ?></textarea><?php echo $error1 ?> <?php echo $error4 ?> <br> Text2: <textarea name="text2" rows="7" cols="30"><? echo $text2; ?></textarea> <?php echo $error2 ?> <?php echo $error5 ?> <br> <input type="submit" name="submit" value="Update News"> </form> <? }//end of while loop }//end else ?> please tell me as soon as possible Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/ Share on other sites More sharing options...
dreamwest Posted June 13, 2009 Share Posted June 13, 2009 elseif{$result = mysql_query"UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect");} } Heres the error, its crying out for help Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-854880 Share on other sites More sharing options...
Maq Posted June 13, 2009 Share Posted June 13, 2009 Do you have an editor with a syntax highlighter? This should have been easy to spot with one. Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-854885 Share on other sites More sharing options...
crystalnano Posted June 13, 2009 Author Share Posted June 13, 2009 Do you have an editor with a syntax highlighter? This should have been easy to spot with one. yes i am using rapid php but error was not corrected elseif ( $result = mysql_query"UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect"); echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=index.php>"; $done="TRUE"; ) is this code is correct? Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-854898 Share on other sites More sharing options...
dreamwest Posted June 13, 2009 Share Posted June 13, 2009 Make another elseif clause based on database input elseif(something){ mysql_query("UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ,$connect"); echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=index.php>"; $done="TRUE"; } Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-854902 Share on other sites More sharing options...
crystalnano Posted June 13, 2009 Author Share Posted June 13, 2009 please not i am newbie i cannot understand Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-854912 Share on other sites More sharing options...
dreamwest Posted June 13, 2009 Share Posted June 13, 2009 looking at your code you dont really need the database elseif Find: elseif{$result = mysql_query"UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect");} } replace: mysql_query("UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect"); Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-854916 Share on other sites More sharing options...
dreamwest Posted June 13, 2009 Share Posted June 13, 2009 There was about 12 errors in this script, ive rewritten it for you <title>Edit News</title> <?php //LAST UPDATE // 27-09-2007 include("config.php"); $newsid = $_GET['newsid']; if(isset($_POST['submit'])){ $title = $_POST['title']; $text1 = $_POST['text1']; $text2 = $_POST['text2']; //check if (title) field is empty then print error message. if(!$title){ //this means If the title is really empty. $error = "Error: News title is a required field. Please fill it."; }elseif ((bool) preg_match('/[0-9]/', $title)) { $error3 = "Error: News title must not contain numbers. Please refill it, with all numbers removed."; }elseif(!$text1){ //this means If the title is really empty. $error1= "Error: News text1 is a required field. Please fill it."; }elseif ((bool) preg_match('/[0-9]/', $text1)) { $error4 = "Error: News title must not contain numbers. Please refill it, with all numbers removed."; }elseif(!$text2){ //this means If the title is really empty. $error2= "Error: News text2 is a required field. Please fill it."; }elseif ((bool) preg_match('/[0-9]/', $text2)) { $error5 = "Error: News title must not contain numbers. Please refill it with all numbers removed."; } mysql_query("UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect); }//end if submit echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=index.php>"; $done="TRUE"; if ($done !="TRUE"){ $result = mysql_query("SELECT * FROM news WHERE newsid='{$newsid}' ",$connect); while($myrow = mysql_fetch_assoc($result)){ $title = $myrow["title"]; $text1 = $myrow["text1"]; $text2= $myrow["text2"]; ?> <br> <h3>::Edit News</h3> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="newsid" value="<? echo $myrow['newsid']?>"> Title: <input name="title" size="40" maxlength="255" value="<? echo $title; ?>"><?php echo $error ?> <?php echo $error3 ?> <br> Text1: <textarea name="text1" rows="7" cols="30"><? echo $text1; ?></textarea><?php echo $error1 ?> <?php echo $error4 ?> <br> Text2: <textarea name="text2" rows="7" cols="30"><? echo $text2; ?></textarea> <?php echo $error2 ?> <?php echo $error5 ?> <br> <input type="submit" name="submit" value="Update News"> </form> <? }//end of while loop }//end else ?> Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-854918 Share on other sites More sharing options...
crystalnano Posted June 14, 2009 Author Share Posted June 14, 2009 your code does not work when i click edit news link it display message "news updated successfully" no edit news form displayed ??? Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-855429 Share on other sites More sharing options...
dreamwest Posted June 14, 2009 Share Posted June 14, 2009 My mistake 13 errors... Change if ($done !="TRUE"){ To if ($done ="TRUE"){ Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-855477 Share on other sites More sharing options...
crystalnano Posted June 14, 2009 Author Share Posted June 14, 2009 now another problem. when i press edit link page displayed that news updated successfully and below this the text boxes appear. now whts wrong ??? Quote Link to comment https://forums.phpfreaks.com/topic/162012-edit-news-error/#findComment-855486 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.