Hi All,

Im currently working on 'localhost'. Whenever i run the following all i get is

<br /><b>Notice</b>: Undefined variable: myrow in <b>C:\wamp\www\testbin\edit\edit.php</b> on line <b>59</b><br />


//connect to mysql
//change user and password to your mySQL name and password
//select which database you want to edit

//If cmd has not been initialized
   //display all the news
   $result = mysql_query("select * from indexinfo WHERE id = 1"); 
   //run the while loop that grabs all the news scripts
	 //make the title a link
      echo "<a href='edit.php?cmd=edit&id=$id'>$Title - Edit</a>";
      echo "<br>";

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
   if (!isset($_POST["submit"]))
      $id = 1;
      $sql = "SELECT * FROM indexinfo WHERE id=$id";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      <form action="edit.php" method="post">
      <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
      Title:<INPUT TYPE="TEXT" NAME="Title" VALUE="<?php echo $myrow["Title"] ?>" SIZE=30><br>
	  Subtitle:<INPUT TYPE="TEXT" NAME="Subtitle" VALUE="<?php echo $myrow["Subtitle"] ?>" SIZE=30><br>
      Content:<TEXTAREA NAME="Content" ROWS=10 COLS=30><? echo $myrow["Content"] ?></TEXTAREA><br>
      Author:<INPUT TYPE="TEXT" NAME="Author" VALUE="<?php echo $myrow["Author"] ?>" SIZE=30><br>
	  Date:<INPUT TYPE="TEXT" NAME="Date" VALUE="<?php echo $myrow["Date"] ?>" SIZE=30><br>
      <input type="hidden" name="cmd" value="edit">
      <input type="submit" name="submit" value="submit">
   <? } ?>
   if ($_POST["$submit"])
      $Title = $_POST["Title"];
      $Subtitle = $_POST["Subtitle"];
      $Content = $_POST["who"];
      $Author = $_POST["Author"];
      $Date = $_POST["Date"];

      $sql = "UPDATE indexinfo SET Title='$Title',Subtitle='$Subtitle',Content='$Content', Author='$Author', Date='$Date' WHERE id=$id";

      $result = mysql_query($sql);
      echo "Thank you! Information updated.";

Probably after line: $myrow = mysql_fetch_array($result);

If the query fails, $myrow will be false instead of an array.


I agree with Pritaeas.

You can test the theory by inserting after $myrow = mysql_fetch_array($result);

	$myrow = array(
		'Title' => 'testTitle',
		'Subtitle' => 'testSubtitle',
		'Content' => 'testContent',
		'Author' => 'testAuthor',
		'Date' 	 => 'testDate'


Useful addition
This article has been dead for over six months. Start a new discussion instead.