Jump to content

Please Fix The Errors In The Code


laado

Recommended Posts

following is a code of edit_news.php

<title>Edit News</title><?php//LAST UPDATE// 27-09-2007include("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.";		 $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>";}	 else		  if($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?>

I want to display error same as display in add_news.php file i.eif the title field is empty error will displayedif the text1 field is empty error will displayedif the text2 field is empty error will displayedif numaric data is add in the title filed error will displayedif numaric data is add in the text1 filed error will displayedif numaric data is add in the text2 filed error will displayedfor example see add_news.php code.

<title>hotnews</title><?php//LAST UPDATE// 27-09-2007include("config.php");$error = "";$error1 = "";$error2 = "";$error3 = "";$error4 = "";$error5 = "";  if(isset($_POST['submit']))  {//begin of if($submit).	  // Set global variables to easier names	  $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.";				 			   } else 	  {		 //run the query which adds the data gathered from the form into the database		 $result = mysql_query("INSERT INTO news (title, dtime, text1, text2)					   VALUES ('$title',NOW(),'$text1','$text2')",$connect);		  //print success message.		  echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";		  echo "<meta http-equiv=Refresh content=4;url=index.php>";				  $done = "TRUE";	  }  }//end of if($submit).  // If the form has not been submitted, display it!if($done != "TRUE")  {//begin of else	  ?>	  <br>	  <h3>::Add News</h3>	  <form method="post" action="<?php echo $_SERVER[PHP_SELF] ?>">	  Title: <input name="title" size="40" maxlength="255"><?php echo $error ?> <?php echo $error3 ?>	  <br>	  Text1: <textarea name="text1"  rows="7"cols="30"></textarea><?php echo $error1 ?> <?php echo $error4 ?>	  <br>	  Text2: <textarea name="text2" rows="7" cols="30"></textarea><?php echo $error2 ?> <?php echo $error5 ?>	  <br>	  <input type="submit" name="submit" value="Add News">	  </form>	  <?  }//end of else    ?>

Link to comment
Share on other sites

try this..

<title>Edit News</title><?php//LAST UPDATE// 27-09-2007include("config.php");$error =  "";   $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.<br />";	  			   }// end of if			  elseif ((bool) preg_match('/[0-9]/', $title)) {				 $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";							   }			  elseif(!$text1){  //this means If the title is really empty.					 $error .= "Error: News text1 is a required field. Please fill it.<br />";							}			  elseif ((bool) preg_match('/[0-9]/', $text1)) {				 $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";							   }			  elseif(!$text2){  //this means If the title is really empty.					 $error .= "Error: News text2 is a required field. Please fill it.<br />";			  			   }	  	 		elseif ((bool) preg_match('/[0-9]/', $text2)) {				 	$error .= "Error: News title must not contain numbers. Please refill it with all numbers removed.<br />";	if($error == "")	{		 $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 HomePage after (4) Seconds";		  echo "<meta http-equiv=Refresh content=4;url=index.php>";		else		{		echo $error;		}}	 else		  if($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; ?>"><?phpecho $error ?><?php echo $error3 ?><br>Text1: <textarea name="text1"  rows="7" cols="30"><? echo $text1; ?></textarea><?phpecho $error1 ?><?php echo $error4 ?><br>Text2: <textarea name="text2" rows="7" cols="30"><? echo $text2; ?></textarea> <?phpecho $error2 ?><?php echo $error5 ?><br><input type="submit" name="submit" value="Update News"></form><?			  }//end of while loop    }//end else?>

Link to comment
Share on other sites

now the error comesParse error: syntax error, unexpected T_ELSE in C:\Program Files\VertrigoServ\www\news\edit_news.php on line 57 now whts wrong?

try this..
<title>Edit News</title><?php//LAST UPDATE// 27-09-2007include("config.php");$error =  "";   $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.<br />";	  			   }// end of if			  elseif ((bool) preg_match('/[0-9]/', $title)) {				 $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";							   }			  elseif(!$text1){  //this means If the title is really empty.					 $error .= "Error: News text1 is a required field. Please fill it.<br />";							}			  elseif ((bool) preg_match('/[0-9]/', $text1)) {				 $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";							   }			  elseif(!$text2){  //this means If the title is really empty.					 $error .= "Error: News text2 is a required field. Please fill it.<br />";			  			   }	  	 		elseif ((bool) preg_match('/[0-9]/', $text2)) {				 	$error .= "Error: News title must not contain numbers. Please refill it with all numbers removed.<br />";	if($error == "")	{		 $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 HomePage after (4) Seconds";		  echo "<meta http-equiv=Refresh content=4;url=index.php>";		else		{		echo $error;		}}	 else		  if($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; ?>"><?phpecho $error ?><?php echo $error3 ?><br>Text1: <textarea name="text1"  rows="7" cols="30"><? echo $text1; ?></textarea><?phpecho $error1 ?><?php echo $error4 ?><br>Text2: <textarea name="text2" rows="7" cols="30"><? echo $text2; ?></textarea> <?phpecho $error2 ?><?php echo $error5 ?><br><input type="submit" name="submit" value="Update News"></form><?			  }//end of while loop    }//end else?>

Link to comment
Share on other sites

echo "<meta http-equiv=Refresh content=4;url=index.php>";else{

change to
echo "<meta http-equiv=Refresh content=4;url=index.php>";}else{

Link to comment
Share on other sites

i'm confused with the placement of your "//end of while loop"anyway i notice you have newsid set with GET and there is a conditional statement involving it, when you load the page with your form it's not setting that so it will skip over that conditional statement.... possibly change GET to REQUEST and use a hidden input form with the value of $newsid

Link to comment
Share on other sites

i cannot understand.can you please exactly tell me wht and where i change in the code.

i'm confused with the placement of your "//end of while loop"anyway i notice you have newsid set with GET and there is a conditional statement involving it, when you load the page with your form it's not setting that so it will skip over that conditional statement.... possibly change GET to REQUEST and use a hidden input form with the value of $newsid
Link to comment
Share on other sites

i see you already have the hidden input.. the only problem is "GET" only reads what is in the URL, not what comes through in POST method form... REQUEST will read both.. sochange your "GET" to "REQUEST"

Link to comment
Share on other sites

i change $newsid = $_GET['newsid']; to $newsid = $_REQUEST['newsid'];but problem still not solved sitll blank white page open.

i see you already have the hidden input.. the only problem is "GET" only reads what is in the URL, not what comes through in POST method form... REQUEST will read both.. sochange your "GET" to "REQUEST"
Link to comment
Share on other sites

does the error msg show up if you don't enter all the info?remove the "else" in this code:

}	 else		  if($newsid){

then post your whole code again, i'm not sure what you got currently
Link to comment
Share on other sites

here is the code

<title>Edit News</title><?php//LAST UPDATE// 27-09-2007include("config.php");$error =  "";   $newsid = $_REQUEST['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.<br />";	  			   }// end of if			  elseif ((bool) preg_match('/[0-9]/', $title)) {				 $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";							   }			  elseif(!$text1){  //this means If the title is really empty.					 $error .= "Error: News text1 is a required field. Please fill it.<br />";							}			  elseif ((bool) preg_match('/[0-9]/', $text1)) {				 $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";							   }			  elseif(!$text2){  //this means If the title is really empty.					 $error .= "Error: News text2 is a required field. Please fill it.<br />";			  			   }	  			 elseif ((bool) preg_match('/[0-9]/', $text2)) {					 $error .= "Error: News title must not contain numbers. Please refill it with all numbers removed.<br />";	if($error == "")	{		 $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 HomePage after (4) Seconds";		  echo "<meta http-equiv=Refresh content=4;url=index.php>";		else		{		echo $error;		}}			  if($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; ?>"><?phpecho $error ?><?php echo $error3 ?><br>Text1: <textarea name="text1"  rows="7" cols="30"><? echo $text1; ?></textarea><?phpecho $error1 ?><?php echo $error4 ?><br>Text2: <textarea name="text2" rows="7" cols="30"><? echo $text2; ?></textarea> <?phpecho $error2 ?><?php echo $error5 ?><br><input type="submit" name="submit" value="Update News"></form><?			  }//end of while loop    }//end else?>

now the error comes:Parse error: syntax error, unexpected T_ELSE in C:\Program Files\VertrigoServ\www\news\edit_news.php on line 57

does the error msg show up if you don't enter all the info?remove the "else" in this code:then post your whole code again, i'm not sure what you got currently
Link to comment
Share on other sites

please tell me whts wrong in the code which else statement is wrong??

here is the code
<title>Edit News</title><?php//LAST UPDATE// 27-09-2007include("config.php");$error =  "";   $newsid = $_REQUEST['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.<br />";	  			   }// end of if			  elseif ((bool) preg_match('/[0-9]/', $title)) {				 $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";							   }			  elseif(!$text1){  //this means If the title is really empty.					 $error .= "Error: News text1 is a required field. Please fill it.<br />";							}			  elseif ((bool) preg_match('/[0-9]/', $text1)) {				 $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";							   }			  elseif(!$text2){  //this means If the title is really empty.					 $error .= "Error: News text2 is a required field. Please fill it.<br />";			  			   }	  			 elseif ((bool) preg_match('/[0-9]/', $text2)) {					 $error .= "Error: News title must not contain numbers. Please refill it with all numbers removed.<br />";	if($error == "")	{		 $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 HomePage after (4) Seconds";		  echo "<meta http-equiv=Refresh content=4;url=index.php>";		else		{		echo $error;		}}			  if($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; ?>"><?phpecho $error ?><?php echo $error3 ?><br>Text1: <textarea name="text1"  rows="7" cols="30"><? echo $text1; ?></textarea><?phpecho $error1 ?><?php echo $error4 ?><br>Text2: <textarea name="text2" rows="7" cols="30"><? echo $text2; ?></textarea> <?phpecho $error2 ?><?php echo $error5 ?><br><input type="submit" name="submit" value="Update News"></form><?			  }//end of while loop    }//end else?>

now the error comes:Parse error: syntax error, unexpected T_ELSE in C:\Program Files\VertrigoServ\www\news\edit_news.php on line 57

Link to comment
Share on other sites

I've had a look at the code and move/altered for and else end brackets + added a select record list, a process variable to identify which areas to show/process record list, edit form and finally update record, and it seems to work.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Edit News</title><?php//LAST UPDATE// 27-09-2007include("config.php");   if(isset($_REQUEST['process']))   		{		$process=$_REQUEST['process'];;		}		else		{		$process=1; //open record list form		}		   if(isset($_REQUEST['newsid']))   		{		$newsid=$_REQUEST['newsid'];		}			   if(isset($_POST['submit']) && $process == 4)  		{      $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.<br />";            }// end of if		elseif ((bool) preg_match('/[0-9]/', $title)) 			{            $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";            }		elseif(!$text1)			{  //this means If the title is really empty.			$error .= "Error: News text1 is a required field. Please fill it.<br />";			}		elseif ((bool) preg_match('/[0-9]/', $text1)) 			{			$error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";			}		elseif(!$text2)			{  //this means If the title is really empty.             $error .= "Error: News text2 is a required field. Please fill it.<br />";        	}      		elseif ((bool) preg_match('/[0-9]/', $text2)) 			{            $error .= "Error: News title must not contain numbers. Please refill it with all numbers removed.<br />";			}						if($error =="")			{			$process=3;  //if no errors process update values			}			else			{			$process=2; //else return to edit form with errors			}							}	 ?> </head><body>   <?php $resultx = mysql_query("SELECT * FROM news ORDER BY newsid");if($process ==1) //open record list form{echo "<form method=\"post\" action=\"".$PHP_SELF."\"><table border=\"1\" cellspacing=\"0\" cellpaddding=\"0\"><tr>";for ($i = 0; $i < mysql_num_fields($resultx); $i++){echo "<th>".strtoUpper(mysql_field_name($resultx, $i))."</th>";}echo "</tr>";$resultx = mysql_query("SELECT * FROM news");while($myrow = mysql_fetch_array($resultx)){echo "<tr>";printf ("<td><center><input type=\"submit\" name=\"newsid\" value=\"%s\"></center></td><td><center>%s</center></td><td><center>%s</center></td><td><center>%s</center></td>",$myrow["newsid"],$myrow["title"],$myrow["text1"],$myrow["text2"]);echo "</tr>";}echo "";echo "</table><input type=\"hidden\" id=\"process\" name=\"process\" value=\"2\" /></form>";}		if($process==3) //process update values    		{			         	$result = mysql_query("UPDATE news SET title='$title', text1='$text1', text2='$text2' WHERE newsid = '$newsid'",$connect);						mysql_query($result);						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>";			}			              	if($newsid && $process==2) //display edit form		{		    	$result = mysql_query("SELECT * FROM news WHERE newsid='$newsid'",$connect);        		while($myrow = mysql_fetch_assoc($result))        	{			if(!$error)			{            $title = $myrow["title"];            $text1 = $myrow["text1"];            $text2= $myrow["text2"];			}?><br /><h3>::Edit News</h3>ID: <?php echo $myrow['newsid']?><form method="post" action="<?php echo $PHP_SELF ?>"><input type="hidden" name="newsid" value="<?php 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" /><input type="hidden" id="process" name="process" value="4" /> <!--process value to validate values--></form><?		}//end of while loop    }//end else?></body></html>

Link to comment
Share on other sites

it still cannot work when i click edit link a page with form open but in that form the text fields are empty and when i enter any thing in the for and then press update button then plank page appear. whts and where wrong

Link to comment
Share on other sites

if you run my code first time, it should list all the field names as header names, and records within the news table itself, whether it is empty of records or not.if the field names (table header) are not listed, then a connection to the database or table is not being achieved. check config for database name, check database table name, field names (newsid (primary, with auto increment), title, text1, text2 (all varchar) is there a index.php for the edit form to go to when update is achieved.where are you running this code? local server, hosting server does it have 'short open tag' <? disabled and only allow <?php start all <? start tags with <?php and see if this fixes the problem (including config.php etc).

Link to comment
Share on other sites

i m using vertrigo server.here is the index.php file:

<title>News----By: maaking.com</title><?php// load the configuration file.include("config.php");		//load all news from the database and then OREDER them by newsid		//you will notice that newlly added news will appeare first.		//also you can OREDER by (dtime) instaed of (news id)		$result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);		//lets make a loop and get all news from the database		while($myrow = mysql_fetch_array($result))			 {//begin of loop			   //now print the results:			   echo "<b>Title: ";			   echo $myrow['title'];			   echo "</b><br>On: <i>";			   echo $myrow['dtime'];			   echo "</i><hr align=left width=160>";			   echo $myrow['text1'];			   // Now print the options to (Read,Edit & Delete the news)			   echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>				|| <a href=\"edit_news.php?newsid=$myrow[newsid]\">Edit</a>				 || <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><hr>";			 }//end of loop?><!-- here you have the right to go Home or Add News. It's HTML not PHP --><br><br><a href=index.php>Home</a> <a href=add_news.php>Add News</a>

database table is ok. now plz tell me whts wrong

if you run my code first time, it should list all the field names as header names, and records within the news table itself, whether it is empty of records or not.if the field names (table header) are not listed, then a connection to the database or table is not being achieved. check config for database name, check database table name, field names (newsid (primary, with auto increment), title, text1, text2 (all varchar) is there a index.php for the edit form to go to when update is achieved.where are you running this code? local server, hosting server does it have 'short open tag' <? disabled and only allow <?php start all <? start tags with <?php and see if this fixes the problem (including config.php etc).
Link to comment
Share on other sites

I've amended index.php link <a href=\"edit_news.php?newsid=$myrow[newsid]\"> to <a href=\"edit_news.php?newsid=$myrow[newsid]&process=2\">and using my edit_news.php code (below) it works fine for me, and hopefully, for you now (cross fingers).index.php code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><?php// load the configuration file.include("config.php");        //load all news from the database and then OREDER them by newsid        //you will notice that newlly added news will appeare first.        //also you can OREDER by (dtime) instaed of (news id)        $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);        //lets make a loop and get all news from the database        while($myrow = mysql_fetch_array($result))             {//begin of loop               //now print the results:               echo "<b>Title: ";               echo $myrow['title'];               echo "</b><br>On: <i>";               echo $myrow['dtime'];               echo "</i><hr align=left width=160>";               echo $myrow['text1'];               // Now print the options to (Read,Edit & Delete the news)               echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>                || <a href=\"edit_news.php?newsid=$myrow[newsid]&process=2\">Edit</a>                 || <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><hr>";             }//end of loop?><!-- here you have the right to go Home or Add News. It's HTML not PHP --><br><br><a href=index.php>Home</a> <a href=add_news.php>Add News</a></body></html>

edit_news.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Edit News</title><?php//LAST UPDATE// 27-09-2007include("config.php");   if(isset($_REQUEST['process']))           {        $process=$_REQUEST['process'];;        }                   if(isset($_REQUEST['newsid']))           {        $newsid=$_REQUEST['newsid'];        }               if(isset($_POST['submit']) && $process == 4)          {      $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.<br />";            }// end of if        elseif ((bool) preg_match('/[0-9]/', $title))             {            $error .= "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br />";            }        elseif(!$text1)            {  //this means If the title is really empty.            $error .= "Error: News text1 is a required field. Please fill it.<br />";            }        elseif ((bool) preg_match('/[0-9]/', $text1))             {            $error .= "Error: News text1 must not contain numbers. Please refill it, with all numbers removed.<br />";            }        elseif(!$text2)            {  //this means If the title is really empty.             $error .= "Error: News text2 is a required field. Please fill it.<br />";            }              elseif ((bool) preg_match('/[0-9]/', $text2))             {            $error .= "Error: News text2 must not contain numbers. Please refill it with all numbers removed.<br />";            }                        if($error =="")            {            $process=3;  //if no errors process update values            }            else            {            $process=2; //else return to edit form with errors            }                            }     ?> <style type="text/css">  table td {padding: 0 10px;}  </style> </head><body>   <?php         if($process==3) //process update values            {                         $result = mysql_query("UPDATE news SET title='$title', text1='$text1', text2='$text2' WHERE newsid = '$newsid'",$connect);                        mysql_query($result);                        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>";            }                              if($newsid && $process==2) //display edit form        {                $result = mysql_query("SELECT * FROM news WHERE newsid='$newsid'",$connect);                while($myrow = mysql_fetch_assoc($result))            {            if(!$error)            {            $title = $myrow["title"];            $text1 = $myrow["text1"];            $text2= $myrow["text2"];            }?><br /><h3>::Edit News</h3>ID: <?php echo $myrow['newsid']?><form method="post" action="<?php echo $PHP_SELF ?>"><input type="hidden" name="newsid" value="<?php 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" /><input type="hidden" id="process" name="process" value="4" /> <!--process value to validate values--></form><?php        }    }?></body></html>

Link to comment
Share on other sites

if you have a list of news items from the index.php page (copied exactly from my code above), the database is being read correct?you click the specific news item edit link which takes you to the edit_news.php (copied exactly from my code above) page correct?you should have something in the address bar similar to this in bold appear:http://mysite/edit_news.php?newsid=2&process=2 correct?this should open the edit form from the edit_news.php page with the specific news selected item to edit.P.S there are three parts of the code in edit_news.php, that might be causing problem <? echo $title; ?> <? echo $text1; ?> <? echo $text2; ?> change these to <?php echo $title; ?> <?php echo $text1; ?> <?php echo $text2; ?>if this does not work, after this, i don't know what is causing problem, can't be the code (unless it is above problem) as it works fine on my PC (with short open tags or not).if it can list the news items in the index page, then the database is ok! it is the passing the value (newsid & process) which seem to be the problem Why? i dont know got me baffled.

Link to comment
Share on other sites

if you have a list of news items from the index.php page (copied exactly from my code above), the database is being read correct?you click the specific news item edit link which takes you to the edit_news.php (copied exactly from my code above) page correct?you should have something in the address bar similar to this in bold appear:http://localhost/news/edit_news.php?newsid=198&process=2all the above are correct with blank white page. i dont know whts the problem

if you have a list of news items from the index.php page (copied exactly from my code above), the database is being read correct?you click the specific news item edit link which takes you to the edit_news.php (copied exactly from my code above) page correct?you should have something in the address bar similar to this in bold appear:http://mysite/edit_news.php?newsid=2&process=2 correct?this should open the edit form from the edit_news.php page with the specific news selected item to edit.P.S there are three parts of the code in edit_news.php, that might be causing problem <? echo $title; ?> <? echo $text1; ?> <? echo $text2; ?> change these to <?php echo $title; ?> <?php echo $text1; ?> <?php echo $text2; ?>if this does not work, after this, i don't know what is causing problem, can't be the code (unless it is above problem) as it works fine on my PC (with short open tags or not).if it can list the news items in the index page, then the database is ok! it is the passing the value (newsid & process) which seem to be the problem Why? i dont know got me baffled.
Link to comment
Share on other sites

OKtry changing echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>|| <a href=\"edit_news.php?newsid=$myrow[newsid]&process=2\">Edit</a>|| <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><hr>";to thisecho "<br><a href=\"read_more.php?newsid=".$myrow['newsid']."\">Read More...</a> || <a href=\"edit_news.php?newsid=".$myrow['newsid']."&process=2\">Edit</a> || <a href=\"delete_news.php?newsid=".$myrow['newsid']."\">Delete</a><br><hr>";or thisecho "<br><a href=\"read_more.php?newsid={$myrow['newsid']}\">Read More...</a> || <a href=\"edit_news.php?newsid={$myrow['newsid']}&process=2\">Edit</a> || <a href=\"delete_news.php?newsid={$myrow['newsid']}\">Delete</a><br><hr>";

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...