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: -
-
-
$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
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. -
if (($row['Time'] == $time) && ($row['SeatNumber'] == $seatnumber))
-
{
-
echo "<br />Please Go back this seat is taken\n";
-
}
-
-
else
-
{
-
...
-
}
-
2 1169
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. -
if (($row['Time'] == $time) && ($row['SeatNumber'] == $seatnumber))
-
{
-
echo "<br />Please Go back this seat is taken\n";
-
}
-
-
else
-
{
-
...
-
}
-
Thanks very much AutumnsDecay your answer worked for me!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ABC |
last post by:
Which statement on the C# has live-as VB's "With" Statement?
|
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
|
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...
|
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
|
by: =?Utf-8?B?RE9UTkVUR1VZ?= |
last post by:
Hello,
In vb.net there is a with statement, Is there are similar constructor in c#?
|
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;...
|
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):
....
|
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...
|
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?...
|
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...
|
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: 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: 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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
|
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...
| |