954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Script errors

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>
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $subtitle; ?>" /></label>
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100><?php echo $content; ?></TEXTAREA>
<label>Author: <input type="text" name="Author" value="<?php echo $author; ?>" /></label>
<label>Date: <input type="text" name="Date" value="<?php echo $date; ?>" /></label>
<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>
<label>Subtitle: <input type="text" name="Subtitle" /></label>
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100></TEXTAREA>
<label>Author: <input type="text" name="Author" /></label>
<label>Date: <input type="text" name="Date" /></label>
<input type="hidden" name="id" />
<input type="submit" value="Submit" name="send" /></p>
</form>
<?php } ?>
whiteyoh
Posting Pro in Training
479 posts since Jun 2009
Reputation Points: 15
Solved Threads: 15
 

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

Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
 

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

Menster
Junior Poster
175 posts since Jun 2009
Reputation Points: 49
Solved Threads: 22
 

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

Josh Connerty
Posting Whiz
342 posts since Apr 2009
Reputation Points: 31
Solved Threads: 27
 

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.

whiteyoh
Posting Pro in Training
479 posts since Jun 2009
Reputation Points: 15
Solved Threads: 15
 

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.
Josh Connerty
Posting Whiz
342 posts since Apr 2009
Reputation Points: 31
Solved Threads: 27
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You