471,594 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 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 2331
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

Post your reply

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

Similar topics

2 posts views Thread by Shun | last post: by
reply views Thread by xkp | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.