I have a form that pulls user submitted data and populates the form so the data can be edited. The script pulls the data into the form ok, but when you edit anything and try to submit it just goes back to the original value. If anyone can help me figure out why its not updating the database will be greatly appreciated.
Code is as follows:
<?php
$connection = mysql_connect("localhost","$database","password")
or die ("Couldn't connect to server.");
$db = mysql_select_db("database", $connection)
or die("Couldn't select database.");
if ($submit) {
$sql = "UPDATE mspicnic SET (id='$id', name='$name, email='$email', phone='$phone', guest='$guest', children='$children' WHERE id='$id')";
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) {
// select row to update
$sql = "SELECT * FROM mspicnic WHERE id='$id' and email='$email'";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$name = $myrow["name"];
$email = $myrow["email"];
$phone = $myrow["phone"];
$guest = $myrow["guest"];
$children = $myrow["children"];
// populate form for editing
?>
<?php
}
?>
<input type="hidden" name="id" value="<?php echo $id ?>">
Name:<input type="Text" name="name" value="<?php echo $name ?>"><br>
Email:<input type="Text" name="email" value="<?php echo $email ?>"><br>
Phone:<input type="Text" name="phone" value="<?php echo $phone ?>"><br>
Guest:<input type="Text" name="guest" value="<?php echo $guest ?>"><br>
Children:<input type="Text" name="children" value="<?php echo $children ?>"><br>
<input type="submit" name="submit" value="Edit RSVP">
</form>