Jump to content

Validating against another field?


Andrew R

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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.