So I am trying to edit a guestbook on a wedding site. I have a page that shows all of my guests who have registered for the wedding. Next to each row I have an edit and delete button. The delete button works, but the entire edit process does not. When I click edit, I then go to the edit.php page, see below:
[code=php]<?php
session_start();
if (@$_SESSION[‘auth’] !=”yes”)
{
header(“Location: login_form.php”);
exit();
}
?>
<?php
$host=”localhost”;
$username=”username”;
$password=”password”;
$db_name=”database”;
// Connect to server and select database.
mysql_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);
mysql_select_db(“$db_name”)or die(“cannot select DB”);
$id = $_GET[‘id’];
$results = mysql_query(“SELECT * FROM guests WHERE id = ‘$id'”);
$rows = mysql_fetch_assoc($results);
?>
<html>
<head>
<link href=”style.css” type=”text/css” rel=”stylesheet”>
</head>
<body>
<div align=”center”>
<form action=”edit_process.php” method=”post”>
<input type=”hidden” name=”id” value=”<?php echo $row[‘id’]; ?>”>
<table width=”70%” cellpadding=”0″ cellspacing=”0″ border=”0″>
<tr>
<td width=”30%”><table width=”100%” cellpadding=”0″ cellspacing=”0″ border=”0″>
<tr>
<td>Guest 1 <input type=”text” value=”<? echo $rows[‘guest_1’]; ?>” name=”guest_1″></td>
</tr>
<tr>
<td>Guest 2 <input type=”text” value=”<? echo $rows[‘guest_2’]; ?>” name=”guest_2″></td>
</tr>
<tr>
<td>Guest 3 <input type=”text” value=”<? echo $rows[‘guest_3’]; ?>” name=”guest_3″></td>
</tr>
<tr>
<td>Guest 4 <input type=”text” value=”<? echo $rows[‘guest_4’]; ?>” name=”guest_4″></td>
</tr>
<tr>
<td>Guest 5 <input type=”text” value=”<? echo $rows[‘guest_5’]; ?>” name=”guest_5″></td>
</tr>
</table></td>
<td width=”70%”><table width=”100%” cellpadding=”0″ cellspacing=”0″ border=”0″>
<tr>
<td>Will Be Attending <input type=”text” value=”<? echo $rows[‘attending’]; ?>” name=”vegetarian”></td>
</tr>
<tr>
<td>Number Vegetarian Meals <input type=”text” value=”<? echo $rows[‘vegetarian’]; ?>” name=”vegetarian”></td>
</tr>
<tr>
<td>How Many People Attending<input type=”text” value=”<? echo $rows[‘total_guests’]; ?>” name=”vegetarian”></td>
</tr>
<tr>
<td>Email Address <input type=”text” value=”<? echo $rows[’email’]; ?>” name=”vegetarian”></td>
</tr>
</table></td>
</tr>
<tr>
<td><input type=”submit” value=”Update”></td>
</tr>
</table>
</form>
</div>
</body>
</html>
In the URL bar it displays the correct id and all of the information pops up in the correct boxes. Here is where it doesn’t work. When I click update, it doesn’t update on the sql server. Here is the code for the edit_process.php :
[code=php]<?php
$host=”localhost”;
$username=”username”;
$password=”password”;
$db_name=”database”;
header(“Location: rsvp_view.php”);
// Connect to server and select database.
mysql_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);
mysql_select_db(“$db_name”)or die(“cannot select DB”);
$id = $_POST[“id”];
$guest_1 = $_POST[‘guest_1’];
$guest_2 = $_POST[‘guest_2’];
$guest_3 = $_POST[‘guest_3’];
$guest_4 = $_POST[‘guest_4’];
$guest_5 = $_POST[‘guest_5’];
$attending = $_POST[‘attending’];
$vegetarian = $_POST[‘vegetarian’];
$total_guests = $_POST[‘total_guests’];
$email = $_POST[’email’];
$query = ‘SELECT * FROM $tbl_name WHERE id = $id’;
mysql_query(“UPDATE guests SET guest_1=’$guest_1′,guest_2=’$guest_2′,guest_3=’$guest_3′.guest_4=’$guest_4′,guest_5=’$guest_5′,attending=’$attending’,vegetarian=’$vegetarian’,total_guests=’$total_guests’,email=’email’ WHERE id=$id”);
echo mysql_error();
?>
Any ideas of why it isn’t working. This is the last piece of the puzzle for this site, so any help will be appreciated.