473,399 Members | 2,278 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,399 software developers and data experts.

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

Hi,

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
  1.  
  2.  
  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");
  5.  
  6. $row=mysql_fetch_array($sqlresult);
  7.  
  8. if ($row['Time']=='$time' AND $row['SeatNumber']=='$seatnumber')
  9. {
  10. echo "<br />Please Go back this seat is taken\n";
  11. }
  12.  
  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");
  20.  
  21. print "<br />This seat is free - proceed";
  22.  
  23. }
  24.  
  25.  
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.

Thanks,

Jordan
Dec 18 '10 #1
1 2478
johny10151981
1,059 1GB
yes your if statement is wrong

Expand|Select|Wrap|Line Numbers
  1. if ($row['Time']=='$time' AND $row['SeatNumber']=='$seatnumber')
  2.  
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

1
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...
2
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(...
0
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...
14
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...
1
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...
3
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:...
0
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...
12
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....
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.