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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jordan Boden
    New Member
    • Dec 2010
    • 13

    #1

    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:

    Code:
     
    
    $sql="SELECT * FROM swinging_ship WHERE Time='$time' AND SeatNumber='$seatnumber'";
    $sqlresult=mysql_query($sql) or die("Could not retreive data from table");
    
    $row=mysql_fetch_array($sqlresult);
    
    if ($row['Time']=='$time' AND $row['SeatNumber']=='$seatnumber')
    {
    echo "<br />Please Go back this seat is taken\n";
    }
    
    else
    {							$sqlstatement="INSERT INTO customer_details (Title, FirstName, MiddleName, LastName, HouseNoName, Address, Town, County, Postcode, TelephoneNumber, Email)
    										   VALUES ('$title','$firstname','$middlename','$lastname','$housenoname','$address','$town','$county','$postcode','$number','$email')";
    							$sql_result=mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL statement");
    							$sqlstatement="INSERT INTO swinging_ship (RideSelection, Time, SeatNumber)
    								   		   VALUES ('$rideselection','$time','$seatnumber')";
    							$sql_result=mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL statement");
    
    print "<br />This seat is free - proceed";
    
    }
    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
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    yes your if statement is wrong

    Code:
    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

    Code:
    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.

    Comment

    Working...