Jump to content

Archived

This topic is now archived and is closed to further replies.

Andrew R

Validating against another field?

Recommended Posts

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

Share this post


Link to post
Share on other sites
And if bpax is larger than pax insert to bpax the value of pax (option1) or output an error(option2)?

[code]<?php

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;

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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.