I have two php functions. deletebooking works fine but the other does not. I’m not sure if it would be better to combine them or not.
I run this which calls the functions. However I cannot get it too run the deletebookingIf function. can anyone see any errors?
$idnumber = $_GET['del'];
if($_GET['del']) {
deletebookingIf($idnumber);
deletebooking($idnumber);
}
function deletebooking($orderID) {
$sql = "DELETE FROM bs_reservations
WHERE id = '".$orderID."'";
$result = mysql_query($sql) or die("oopsy, error when tryin to delete events 2");
}
function deletebookingIf($orderID) {
$sql = "SELECT DURATION
FROM bs_reservations
WHERE id = '".$orderID."'";
$result = mysql_query($sql) or die("oopsy, error when tryin to delete events 2");
if ($result != "One Day Rental") {
$orderID2 = $orderID - 1;
$qq = "DELETE FROM bs_reservations
WHERE id = '".$orderID2."'";
$result = mysql_query($qq) or die("oopsy, error when tryin to delete events 2");
}
}
Instead of
You should have:
$result contains a set of rows, not the contents of a field. If that id isn’t a primary key, you should also use LIMIT 1 in your query to make sure you return only one line. You should also use mysql_num_rows($result) to make sure you do have an entry for that id.
Good luck!