dessolator Posted February 3, 2008 Share Posted February 3, 2008 Hi, I have a form on a page where a user enters their booking id which is then passed over to the next page so that their booking id can be deleted from the database where their user id = something. The script is deleting the booking id if it exists where userid= something but when their is no match in the database I want it to display a error message but for some reason I can't get it to show it and it is just displaying booking cancelled. I have tried fetch_array and num rows and still can't get it to work. <?php session_start(); $session_username = $_SESSION['myusername']; $reason = substr($_POST['reason'], 0, 65); $booking_id = substr($_POST['bookingid'], 0, 65); $host="localhost"; // Host name $username="root"; // Mysql username $password="abc123"; // Mysql password $db_name="colab_booking"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //Database - Assigns the below statement into the variable query $query = "SELECT * FROM members WHERE username = '$session_username'"; $result = mysql_query($query); $count=mysql_num_rows($result); if($count==1){ $user_id = $row[0]; mysql_query("DELETE FROM `bookings` WHERE `booking_id` = '$booking_id' AND `member_id` = '$user_id'"); echo "Reservation sucessfully cancelled"; } else{ echo "The booking id you entered is not vaid please check it and try again."; exit(0); } ?> I would appreciate your help. Thanks, Ian Link to comment https://forums.phpfreaks.com/topic/89221-else-statement-not-working/ Share on other sites More sharing options...
affordit Posted February 3, 2008 Share Posted February 3, 2008 Try this: if($count==1){ $user_id = $row[0]; mysql_query("DELETE FROM `bookings` WHERE `booking_id` = '$booking_id' AND `member_id` = '$user_id'"); echo "Reservation sucessfully cancelled"; } elseif($count==0){ echo "The booking id you entered is not vaid please check it and try again."; exit(0); } Link to comment https://forums.phpfreaks.com/topic/89221-else-statement-not-working/#findComment-456864 Share on other sites More sharing options...
dessolator Posted February 3, 2008 Author Share Posted February 3, 2008 Hi, thanks for your reply. I tried that and its still comming up saying Reservation sucessfully cancelled instead of the error message. This is wierd I swear that syntax should work. ??? Thanks, Ian Link to comment https://forums.phpfreaks.com/topic/89221-else-statement-not-working/#findComment-456870 Share on other sites More sharing options...
revraz Posted February 3, 2008 Share Posted February 3, 2008 You know you are basing your IF count result on $query = "SELECT * FROM members WHERE username = '$session_username'"; right? Link to comment https://forums.phpfreaks.com/topic/89221-else-statement-not-working/#findComment-456883 Share on other sites More sharing options...
dessolator Posted February 3, 2008 Author Share Posted February 3, 2008 Thanks for your reply, Basically i'm getting the username from the session then I want to lookup in the members table to get the member_id so that I can identify them in the bookings table as this only has booking id, member id and event id in. But I can't think of the way to do it as I thought the count would check for matching rows. Any pointers on how to do this? Thanks, Ian Link to comment https://forums.phpfreaks.com/topic/89221-else-statement-not-working/#findComment-456938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.