Hi All,

I am trying to display the content of a single row from MySql with the following code but the echo is displaying nothing at all. Please can you advise as to where i can find the error?

I have a feeling its something to do with the loop, as in effect there is no loop required, but on removing it i get an error.

Any help you can give is greatly appreciated.

Here is the code:

<?

// Select all data records in table "name_list" and put them into $result.
$result=mysql_query("SELECT * from `indexinfo` WHERE id = '1'");

//store the queried cell in the variable 
//named $result 

$result = mysql_query($sql_query);  

//display the queried cell 

$row = mysql_fetch_array($result); 
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="update.php">
<table border="1" cellpadding="3" cellspacing="0">
<tr>

<td align="center" bgcolor="#FFCC00"><strong>id</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Title</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Subtitle</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Content</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Author</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Date</strong></td>
</tr>



<? echo $row['id']; ?>
<? echo $row['Title']; ?>
<? echo $row['Subtitle']; ?>
<? echo $row['Content']; ?>
<? echo $row['Author']; ?>
<? echo $row['Date']; ?>


</table>
<input type="submit" name="Submit" value="Update" />
</form>
</body>
</html>

Hi there,
I think i've spotted your problem.

<?
// Select all data records in table "name_list" and put them into $result.
$result=mysql_query("SELECT * from `indexinfo` WHERE id = '1'");

//store the queried cell in the variable 
//named $result 

$result = mysql_query($sql_query);

After you run the initial query and store the result set in "$result"
you re-assign "$result" to "mysql_query($sql_query)" where "$sql_query" is an uninitialised variable and empty, so when the time comes that you want to fetch the row, your "$result" variable is pointing at nothing. .*. you get no content displayed.

Hope this helped,

Hi Thanks for that, i have it displaying now.

My next questions is now that I have the data displaying in an editable fashion, i have included the "updatei1.php" file but it just produces a plank screen. The first piece of code is editing area, the second is the update area. Are you able to assist?

<form action="updatei1.php" method="post">
<input type="hidden" name="id" value="<?php echo $row["id"] ?>" />
<input type="text" name="Title" value="<?php echo $row["Title"]?>" />
<br />
<input type="text" name="Subtitle" value="<?php echo $row["Subtitle"] ?>" />
<br />
<textarea name="Content" rows=10 cols=100><?php echo $row["Content"]?></textarea> </br>
Author <input type="text" name="Author" value="<?php echo $row["Author"] ?>" />
Date<input type="text" name="Date" value="<?php echo $row["Date"] ?>" />


<br />
<br />
<input type="submit" name="submit" />
<?
   if ($_POST["$submit"])
   {
      $id = $_POST["id"];
      $Title = $_POST["Title"];
      $Subtitle = $_POST["Subtitle"];
      $Content = $_POST["Content"];
      $Author = $_POST["Author"];
      $Date = $_POST["Date"];

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

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

It looks like you have an unneeded dollar sign in your 'if' condition. Try changing if ($_POST["$submit"]) to this if ($_POST["submit"]) . Just my 2 cents.

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