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
mysql_connect("localhost","----","----"); 
	
//select which database you want to edit
mysql_select_db("silverlink"); 

//If cmd has not been initialized
if(!isset($cmd)) 
{
   //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">
   
      </form>
   
   <? } ?>
<?
   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.";
   }
}
?>

Recommended Answers

All 4 Replies

Whiteyoh,

Which is line 59?

Airshow

it is all of the form PHP echos

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

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

Whiteyoh,

I agree with Pritaeas.

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

if(!$myrow){
	$myrow = array(
		'Title' => 'testTitle',
		'Subtitle' => 'testSubtitle',
		'Content' => 'testContent',
		'Author' => 'testAuthor',
		'Date' 	 => 'testDate'
	)
}

Airshow

commented: Useful addition +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.