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

need help with an if statement

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. {
  15. $sqlstatement="INSERT INTO customer_details (Title, FirstName, MiddleName, LastName, HouseNoName, Address, Town, County, Postcode, TelephoneNumber, Email)
  16.                                            VALUES ('$title','$firstname','$middlename','$lastname','$housenoname','$address','$town','$county','$postcode','$number','$email')";
  17.                             $sql_result=mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL statement");
  18.  
  19. $sqlstatement="INSERT INTO swinging_ship (RideSelection, Time, SeatNumber)
  20.                                               VALUES ('$rideselection','$time','$seatnumber')";
  21.                             $sql_result=mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL statement");
  22.  
  23. print "<br />This seat is free - proceed";
  24.  
  25. }
  26.  
  27.  
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 19 '10 #1

✓ answered by AutumnsDecay

You have quotes around your variables in the if statement. Your statement was also formatted incorrectly for multiple comparisons.

And while it's not "wrong", I would put logical operators instead of words (ie. '&&' instead of 'AND').

This is what it should look like.

Expand|Select|Wrap|Line Numbers
  1. if (($row['Time'] == $time) && ($row['SeatNumber'] == $seatnumber))
  2. {
  3. echo "<br />Please Go back this seat is taken\n";
  4. }
  5.  
  6. else
  7. {
  8.  ...
  9. }
  10.  

2 1169
AutumnsDecay
170 100+
You have quotes around your variables in the if statement. Your statement was also formatted incorrectly for multiple comparisons.

And while it's not "wrong", I would put logical operators instead of words (ie. '&&' instead of 'AND').

This is what it should look like.

Expand|Select|Wrap|Line Numbers
  1. if (($row['Time'] == $time) && ($row['SeatNumber'] == $seatnumber))
  2. {
  3. echo "<br />Please Go back this seat is taken\n";
  4. }
  5.  
  6. else
  7. {
  8.  ...
  9. }
  10.  
Dec 20 '10 #2
Thanks very much AutumnsDecay your answer worked for me!
Dec 21 '10 #3

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

Similar topics

2
by: ABC | last post by:
Which statement on the C# has live-as VB's "With" Statement?
4
by: doodle | last post by:
access 97 can someone tell me the syntax for a with stement for multiple controls? pseudo (doesn't work) With cmbBox1,cmbBox2,cmbBox3 .Visible = False End With
3
by: Ashok Guduru | last post by:
Hi, I'm new to C#. In VB.NET we have With...End With Statement. Often, I need to perform several different actions on the same object. For example, I may need to set several properties or...
1
by: Gunawan | last post by:
Hi All, When using vb I could use with statement to make access to property/method shorter Dim cmd AS new SqlCommand with cmd.parameters .AddWithValue() .... end with
33
by: =?Utf-8?B?RE9UTkVUR1VZ?= | last post by:
Hello, In vb.net there is a with statement, Is there are similar constructor in c#?
11
by: Nhan | last post by:
Hi, is there equivalent statement in C# as WITH ... END in VB? instead of: frm.dataGridView1.AutoGenerateColumns = true; frm.dataGridView1.DataSource = l_oDataset;...
2
by: Dmitry Teslenko | last post by:
Hello! I've made some class that can be used with "with statement". It looks this way: class chdir_to_file( object ): .... def __enter__(self): .... def __exit__(self, type, val, tb): ....
2
by: mk | last post by:
Hello, I'm trying to learn how with statement can be used to avoid writing: prepare() try: something_that_can_raise_SomeException() except SomeException, err: deal_with_SomeException...
4
by: braver | last post by:
Can open two files in a with statement: with open(src) as readin, open(dst,"w") as writin: # WRONG: comma doesn't work ... -- so that you have transactional safety for two file descriptors?...
5
by: peppergrower | last post by:
I've been experimenting with the 'with' statement (in __future__), and so far I like it. However, I can't get it to work with a cStringIO object. Here's a minimum working example: ### from...
0
isladogs
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...
1
isladogs
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.