I am writing an administration page for a guestbook. What the admin page does is lets the administrator view the messages that are not authorised, then I want it to be able to change the value of authorised from No to Yes. The cdoe I have for doing that is below. My problem is that when i press add to database, instead of changing the value of authorised, an new record is created (with all the same data) except the id has been incrimented, and authorised is set to Yes. The origional record remains. Could somebody please explain what I am doing wrong - I don't want a new record to be created, I just want the origional record to be updated.
<?php
if ($id) {
$sql = "UPDATE `guestbook` SET name='$name',location='$location',email='$email',check='$check',homepage='$homepage',comment='$comment',ip='$ip',date_time='$date_time',authorised='Yes' WHERE `id`='$id'";
print $sql;
}
// run SQL against the DB
$result = mysql_query($sql);
?>
<?php
if ($id) {
$sql = "UPDATE guestbook SET name='$name',location='$location',email='$email',check='$check',homepage='$homepage',comment='$comment',ip='$ip',date_time='$date_time',authorised='Yes' WHERE `id`=".$id;
print $sql;
}
// run SQL against the DB
$result = mysql_query($sql);
?>
<?php
if (!empty($id)) {
$sql = "UPDATE guestbook SET authorised='Yes' WHERE `id`=".$id;
// run SQL against the DB
@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
}
?>
Thanks, I eventually found the error myself, the person who origionally wrote this page had 2 tables in the database, and so did not require to pass $id via the form, i simply added a hidden field with <?php print $id; ?> and it worked great. Thanks a lot!