Hi,

Firstly apologies as i shouldnt have set a previous thread as solved.

The following script should:

1. get record with id of 1 and display in text box
2. after user changes it, it is written to mysql
3. the screen informs user that this has been achieved

<?php
$result = mysql_query("select * from indexinfo  where id = 1");
$row = mysql_fetch_assoc($result);
if ( isset( $_POST['send'] ) ) {
  // The author's details have been updated.

  
  $title = $_POST['Title'];
  $subtitle = $_POST['Subtitle'];
  $content = $_POST['Content'];
  $author = $_POST['Author'];
  $date = $_POST['Date'];
  $id = $_POST['id'];

  $sql = "UPDATE `indexinfo` SET
          `Title` = '$title',
          `Subtitle` = '$subtitle',
	    `Content` = '$content',
	    `Author` = '$author',
          `Date` = '$date'
          WHERE `id` = '$id'";
  if (mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }

?>


<form action="#" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" value="<?php echo $title; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $subtitle; ?>" /></label><br />
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100><?php echo $content; ?></TEXTAREA><br />
<label>Author: <input type="text" name="Author" value="<?php echo $author; ?>" /></label><br />
<label>Date: <input type="text" name="Date" value="<?php echo $date; ?>" /></label><br />
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="submit" value="Submit" name="send" /></p>



</form>
<?php
} else {
?>
<form action="#" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" /></label><br />
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100></TEXTAREA><br />
<label>Author: <input type="text" name="Author" /></label><br />
<label>Date: <input type="text" name="Date" /></label><br />
<input type="hidden" name="id" />
<input type="submit" value="Submit" name="send" /></p>
</form>
<?php } ?>

It'd help if you told us what errors you're getting.

Hi there,
You don't actually have a problem statement in your post, so I'm not really sure where you are going wrong.

But, I notice that after querying the database at the top of the file, you don't do anything with the $row variable, which is why you aren't seeing anything in your form the first time you load the page.

Hope this helped

What do you mean as in if you haven't submitted the form you still get the row updated message?

The form itself displays each of the headers.... title, subtitle, content, author and date..... but it doesnt echo the data that is held in the mysql database.

On changing the cell information and clicking submit, a success message is given, but the row in the database is not updated.

The form itself displays each of the headers.... title, subtitle, content, author and date..... but it doesnt echo the data that is held in the mysql database.

On changing the cell information and clicking submit, a success message is given, but the row in the database is not updated.

Okay in that case, please add the following at the end of your update query.

$query = mysql_query("QUERY") or die( "UPDATE ERROR:" . mysql_error() );
// QUERY being the update query you have been using.
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.