Andrew R Posted October 9, 2006 Share Posted October 9, 2006 Ok the below script does the following. From a form it inserts the total passengers into the field bPAX. [code]<?if(isset($_POST['update'])){$total_pax = addslashes(trim($_POST['total_pax']));include 'db.php';$sql = "SELECT * FROM routes WHERE flight_id = '$flight_id'";$result = mysql_query($sql);$routes_array = mysql_fetch_array($result);//add pax to bPAX$bPAX = $routes_array['bPAX'];$newtotal = $bPAX + $total_pax;mysql_query("UPDATE routes SET bPAX = '$newtotal' WHERE flight_id = '$flight_id'");mysql_close($connection);}echo 'YOUR BOOKING HAS BEEN PROCESSED';}?>[/code]The problem I am having is that I also have a field "PAX" which is the total capacity for the aircraft say 212. So for example when somebody submits the form with say 215 passengers it will still add that to the bPAX field (which I don't want). How would I write up a script or an ‘if’ statement so that if the total capacity for the aircraft is 212 (PAX field) and somebody enters 215 (for the bPAX field) it will not let insert that many into the database. Maybe some sort of check against the both field? Cheers Quote Link to comment Share on other sites More sharing options...
Orio Posted October 9, 2006 Share Posted October 9, 2006 And if bpax is larger than pax insert to bpax the value of pax (option1) or output an error(option2)?[code]<?phpif(isset($_POST['update'])){$total_pax = addslashes(trim($_POST['total_pax']));include 'db.php';$sql = "SELECT * FROM routes WHERE flight_id = '$flight_id'";$result = mysql_query($sql);$routes_array = mysql_fetch_array($result);//add pax to bPAX$bPAX = $routes_array['bPAX'];$newtotal = $bPAX + $total_pax;if($newtotal <= $routes_array['PAX']) mysql_query("UPDATE routes SET bPAX = '$newtotal' WHERE flight_id = '$flight_id'");else //Option 1- mysql_query("UPDATE routes SET bPAX = '$routes_array['PAX']' WHERE flight_id = '$flight_id'"); //Option 2- die("bPAX cant be bigger than pax");mysql_close($connection);}echo 'YOUR BOOKING HAS BEEN PROCESSED';}?>[/code] Quote Link to comment Share on other sites More sharing options...
Andrew R Posted October 9, 2006 Author Share Posted October 9, 2006 Yes output an errorThank you very much Orio :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.