Hi there. I'm squeeky-new to PHP and trying to write a program that would find out if a user has a limo, and allow them to assign themselves a limo if they don't. The first part sort of works (see below); I'm guessing because it's a pretty easy if...then statement (either they have a limo or they don't). The second part is where things get wonky. The page displays the last known code, apparently, so that if the previous user on a computer has a limo, limo number 1, for example, that comes up initially, even if the next user has no limo assigned. The next user has to hit the browser's refresh to see an accurate display. Next, when they request a limo, the page is not updated to show the request until they request a limo again or hit the browser's refresh button. Finally, if they hit the browser's refresh button again or click on "Revise" the limo number is advanced to the next limo when it shouldn't be. I realize this is a little verbose, and I apologize for that. Here's the code:
<?php
// Declare a variable that holds the connection information
$con = mysql_connect("");
// If unable to connect, die with an error
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Connect to the database
mysql_select_db("", $con);
// Get the email cookie info and assign it to a variable
$email = $_COOKIE['email'];
/* Determine if there is anything in the limo_number field
of the member traveling table, assign it to a variable */
$result = mysql_query("SELECT * FROM member_traveling WHERE email ='$email'");
while ($row = mysql_fetch_array($result))
{
$limo = $row['limo_number'];
// Get the flight number and assign it to a variable
$flight = $row['flight'];
}
/* Find out if the customer is or is not already
scheduled to take a limo and store the result in a variable */
if (!($limo) or empty($limo)){echo 'You are not currently scheduled for a limo.<br />';}
else {echo 'You are scheduled for limo #' . $limo . '.<br />';}
// Connect to our database and list limos that are part of the pool
/* Match the flight number with other members' flight numbers
and display the matches - here is where we use the flight variable */
$result = mysql_query("SELECT * FROM member_traveling WHERE flight='$flight'");
// List all matches for the flight number
while ($row = mysql_fetch_array($result))
{
// If the flight number matches and they have something in the limo number field, list them
if (!empty($row['limo_number']))
{
echo 'Limo Number: '.$row["limo_number"].'
Email: <a href="mailto:'.$row["email"].'">'.$row["email"].'</a><br />';
}
}
// Allow the customer to request a limo
if ($limo == "") {
echo '<form method="post" action="showlimo.php">
<input type="submit" name="get_limo" value="Request a Limo" />
<input type="hidden" name="limo_count" value="0" /></form>';
}
// Or allow them to revise plans if they already have a limo requested
else {
echo '<form method="post" action="showlimo.php">
<input type="submit" name="revise" value="Revise Plans" />
<input type="hidden" name="limo_count" value="1" /></form>';
}
/* If they clicked on "get_limo" put the limo number in the itp table,
update the member traveling table, and delete the limo from the free limo table */
if (isset ($_POST['get_limo'])) {
$query = mysql_query("SELECT limo_number FROM free_limos LIMIT 1");
$limnum = mysql_result($query,0);
mysql_query("INSERT INTO itp_limos SET limo_number='".$limnum."';");
mysql_query("UPDATE member_traveling SET limo_number='".$limnum."',requested='1'
WHERE email='".$email."' LIMIT 1;");
mysql_query("DELETE FROM free_limos WHERE limo_number='".$limnum."' LIMIT 1;");
}
else {echo 'You already have a limo.';}
// Close the connection
mysql_close($con);
?>
Any help that can be provided on this is greatly appreciated.
Thank you!