I'm trying to use two buttons on a single form. One for updating, one for deleting. The update function works fine, but the delete button just posts back. I know the Delete value is in the form post variables when the delete button is clicked as I can write it to the page after posting back....
Any ideas why the delete function isn't working?
The crux of the code is:
Code: Select all
if (isset($_POST["Update"])) {
$updateSQL = sprintf("UPDATE tblreservations SET AgentID=%s WHERE ReservationID=%s",
GetSQLValueString($_POST['AgentID'], "int"),
GetSQLValueString($_POST['ReservationID'], "int"));
mysql_select_db($database_connDB, $connDB);
$Result1 = mysql_query($updateSQL, $connDB) or die(mysql_error());
$updateGoTo = "bookings_edit.php?m=edited";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
} elseif (isset($_POST["Delete"])) {
$updateSQL = sprintf("DELETE FROM tblreservations WHERE tblreservations.ReservationID=%s LIMIT 1",
GetSQLValueString($_POST['ReservationID'], "int"));
mysql_select_db($database_connDB, $connDB);
$Result1 = mysql_query($updateSQL, $connDB) or die(mysql_error());
$updateGoTo = "bookings_edit.php?m=deleted";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
}
header(sprintf("Location: %s", $updateGoTo));
}Code: Select all
<form action="bookings_edit.php" method="post" name="form1" id="form1">
form fields in here
<input type="Submit" name="Update" value="Update" /> <input type="Submit" name="Delete" value="Delete" onclick="if (! confirm('Are you sure?')) { return false; }" />
<input type="hidden" name="ReservationID" value="<?php echo $row_rsBookingToEdit['ReservationID']; ?>" />
</form>