jeffshen Posted April 7, 2010 Share Posted April 7, 2010 <?php if (!isset($_GET['flightid'])) { echo "<table width='100%'><tr><td> </td></tr><tr><td><span class='boldblue'>There has been a problem. <br /><a href='index1.php?page=ivaorfe2010'>Please click here to book another flight.</a></span></td></tr><tr><td> </td></tr></table>"; } else { $flightid = $_GET['flightid']; $query1 = mysql_query("SELECT `pilot_id` FROM `ivaorfetmp` WHERE `flightno` = '$flightid'"); $result1 = mysql_result($query1,0); $pilot_id = $flyuk->pilotid; if ( $result1 == '' || empty($result1) ) { $query2 = "UPDATE ivaorfetmp SET pilot_id = '$pilot_id' WHERE flightno = '$flightid' LIMIT 1"; mysql_query($query2); echo "<table width='100%'><tr><td> </td></tr><tr><td><span class='boldblue'>Your flight has been booked successfully.<br />You will be redirected to your 'My Bookings' page in 3 seconds...</span></td></tr><tr><td></td></tr></table>"; echo "<script type='text/javascript'>"; echo "setTimeout(\"window.location.href = 'index.php?page=my_booked_flights';\", 3000);"; echo "</script>"; } else { echo "<table width='100%'><tr><td> </td></tr><tr><td><span class='boldblue'>The flight has been booked already by ".$result1.". <br /><a href='index1.php?page=ivaorfe2010'>Please click here to book another flight.</a></span></td></tr><tr><td> </td></tr></table>"; } } ?> What I am trying to do with this script is 1. if flightid is not passed in the URL -> produce @There has been a problem. Please click here to book another flight." 2. see whether pilot_id in the mysql table is empty with respect to a flight number which equals the flight id 3. If it is empty, then put the pilot_id in and echo the message and javascript 4. If it is not empty, then echo the message The flight has been booked already by ".$result1.". Please click here to book another flight. What the above script does is: When there is no flightid passed, it produces the correct error message When there is a flightid passed, it runs UPDATE ivaorfetmp SET pilot_id = '$pilot_id' WHERE flightno = '$flightid' LIMIT 1 no problem and inserts the pilot_id, then it shows me The flight has been booked already by ".$result1.". Please click here to book another flight, with $result1 being filled in with the pilot_id I just put into the database. I am sure there isnt any file acting on the database and it is very confusing, as I only run the script once and dont refresh the page. I have even put in extra javascript alert boxes to see whether more than 1 box comes up and it dosent. Does anybody know how I can fix this? Thank you very much in advance, Link to comment https://forums.phpfreaks.com/topic/197824-code-is-working-backwards/ Share on other sites More sharing options...
teamatomic Posted April 7, 2010 Share Posted April 7, 2010 $pilot_id = $flyuk->pilotid; Try to echo out $pilot_id. What do you get? HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/197824-code-is-working-backwards/#findComment-1038134 Share on other sites More sharing options...
jeffshen Posted April 7, 2010 Author Share Posted April 7, 2010 The correct value that is supposed to go into the UPDATE query. This then also becomes the $result1 value for some odd reason when it loads up the error The flight has been booked already by ".$result1.". Please click here to book another flight. I am very certain that when $result1 is defined $result1 = mysql_result($query1,0);, it should come up with an empty string as there is nothing stored on the mysql backend. Link to comment https://forums.phpfreaks.com/topic/197824-code-is-working-backwards/#findComment-1038150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.