473,246 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

I have a problem preventing double booking of a ride using php and mysql


I have a problem trying to prevent a time slot and seat number being double booked. I am using PHP and MySQL for this. Currently I have no errors concerning variable names or issues with inserting data into the database. The only problem I seem to have involves preventing a certain seat number and time from being double booked. I have tried numerous things and I think the problem lies within my 'if' statement so i have shown a snippet of this below:

Expand|Select|Wrap|Line Numbers
  3. $sql="SELECT * FROM swinging_ship WHERE Time='$time' AND SeatNumber='$seatnumber'";
  4. $sqlresult=mysql_query($sql) or die("Could not retreive data from table");
  6. $row=mysql_fetch_array($sqlresult);
  8. if ($row['Time']=='$time' AND $row['SeatNumber']=='$seatnumber')
  9. {
  10. echo "<br />Please Go back this seat is taken\n";
  11. }
  13. else
  14. {                            $sqlstatement="INSERT INTO customer_details (Title, FirstName, MiddleName, LastName, HouseNoName, Address, Town, County, Postcode, TelephoneNumber, Email)
  15.                                            VALUES ('$title','$firstname','$middlename','$lastname','$housenoname','$address','$town','$county','$postcode','$number','$email')";
  16.                             $sql_result=mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL statement");
  17.                             $sqlstatement="INSERT INTO swinging_ship (RideSelection, Time, SeatNumber)
  18.                                               VALUES ('$rideselection','$time','$seatnumber')";
  19.                             $sql_result=mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL statement");
  21. print "<br />This seat is free - proceed";
  23. }
Like I said all my variable names and SQL commands are working and the data is being inserted into the correct database tables and fields. The only problem is preventing the time and seat number from being double booked. I am a noob when it comes to PHP and MySQL so any feedback is much appreciated.


Dec 18 '10 #1
1 2467
1,059 1GB
yes your if statement is wrong

Expand|Select|Wrap|Line Numbers
  1. if ($row['Time']=='$time' AND $row['SeatNumber']=='$seatnumber')
when you insert a variable in single quotes that is not a variable at all. That is a regular string.

So, Try the statement below

Expand|Select|Wrap|Line Numbers
  1. if ($row['Time']==$time AND $row['SeatNumber']==$seatnumber)
But You can ask about they sql query. It seems the variable is in single quote. The answer is no, the variable is in the double quote. cause the single quote you are using is also inside the double quote. So, that single quote is not making any effect.
Dec 20 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: encohen | last post by:
There have been several posts on having MS Access using MySQL as the backend db. I know that you have to set up an ODBC connection and use the MySQL odbc driver. What I want to know is how to set up...
by: Shun | last post by:
Hello, I am new to .net Platform. I want to build a sample application using VB.net and backend mysql. now my problem is how to connect to the mysql database. which is the better provider(...
by: xkp | last post by:
Hi all, i just had to install the 5.0 version of mysql. previously i used an old 3."something" (my server crashed so i dont remember the precise version). I used to access mysql database using...
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one...
by: WebNewbie | last post by:
Hi, I am new to using mysql and there isn't any tutorials online on that shows how to create mysql stored procedure for paging purposes. Thus, I read tutorials on creating stored proc that were...
by: anotherjoe | last post by:
Question 1: I have reservation database in access 2007 I have a cabin information table with: cabinid (primarykey) cabinname(text) cabinlocation(text) I have a customer table with:...
by: John Kirkpatrick | last post by:
Hi all, I am having difficulty displaying records on a frontend MS Access 2000 form using a MySQL backend. The following code works well with the Jet database engine but doesn't work properly...
by: mfaisalwarraich | last post by:
Hi everybody, I am trying to make a EER diagram using mysql workbench to start with a database. This is a vehicle parts database dat im trying to design. i have following five tables: 1....
by: mirasol | last post by:
i am new here,i just want to ask question about uploading file with textbox using mysql and php, i used the codes given by some member and my problem is i dont know how to add textbox and i want it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.