PDA

View Full Version : Form not working how it should


cocoonfx
03-21-2009, 08:00 PM
Hello chaps


I have created a database which i want to perform a calculation if some of the variables match.

In the DB i have Departure, Arrival, Distance

On the form i have the same fields as above plus a weight field, in a form and if the details match i want the form to calculate the formula.

i.e AMS to DXB 10kgs

I then want the form to look for AMS and DXB and then do

Distance*10

And then display this in the form.

Code below.


<?PHP include("includes/connect.php");



$query =sprintf("SELECT * FROM CO2_KM");
$result =mysql_query($query,$dbh);
$row = mysql_fetch_array($result);



$departure = $_POST['Depature'];
$arrival = $_POST['arrival'];
$weight =$_POST['weight'];
$submit = $_POST['submit'];
$reset = $_POST['reset'];


if($departure && $arrival && $submit && $weight){
$c= round($weight*10);
}else{
$c= "0";
}

?>

<form id="form1" name="co2" method="Post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label for="Departure">Departure Airport (IATA 3 letter code i.e London = LHR)</label>
<input type="text" name="Departure" id="Departure"/>
<label for="arrival">Arrival Airport (IATA 3 letter code i.e Paris= CDG)</label>
<input type="text" name="arrival" id="arrival" />
<label for="weight">Gross Weight (Kgs) (10kgs = 10)</label>
<input type="text" name="weight" id="weight" />
<label for="co2">Estimated C02 (Total Kgs)</label>
<input type="text" name="co2" id="co2"value="<?php echo $c;?>"/>
<div align="center"><br>
<input type="submit" value="Submit" class="buttonSubmit" />
<input name="submit" type="hidden" id="submit" value="1" />

</form>

For some reason i can not get the formula to work. I am struggling to work out what i am doing wrong.

Any idea?

davidj
03-21-2009, 10:41 PM
is the formula not working at all?

davidj
03-21-2009, 10:41 PM
are the conditions working

cocoonfx
03-21-2009, 10:49 PM
Hello Dj


No not at all, i thought it would be quite straight forward.

I have also tried

$a= $row['departure'] == $departure;
$b= $row['arrival'] == $arrival;

And this still doesn't work. I have not done php and mysql for months so i am very rusty.....

davidj
03-21-2009, 10:50 PM
try echoing a bit of text inside the condition to see if its working

davidj
03-21-2009, 10:51 PM
this is invalid

$a= $row['departure'] == $departure;
$b= $row['arrival'] == $arrival;

davidj
03-21-2009, 10:54 PM
you method in the form is defined as Post

try changing it to post

lowercase

cocoonfx
03-22-2009, 12:27 AM
ok i have changed the post, and i tried to echo the first field. But it would only work for the first field entry the rest did not work.

Does it matter that i have 300 lines of data?

cocoonfx
03-22-2009, 03:09 AM
All sorted now.... it was quite strange

$query =sprintf("SELECT * FROM CO2_KM_NMilage where DepartureCode='$DepartureCode' and ArrivalCode='$ArrivalCode'");
$result =mysql_query($query,$dbh);
$row = mysql_fetch_array($result);



$a = $row['DepartureCode'] = $DepartureCode;
$b = $row['ArrivalCode'] = $ArrivalCode;

davidj
03-22-2009, 12:26 PM
i dont know what this is doing


$a = $row['DepartureCode'] = $DepartureCode;
$b = $row['ArrivalCode'] = $ArrivalCode;

davidj
03-22-2009, 12:27 PM
are you setting 2 vars at the same time with the same value?

never seen this before

cocoonfx
03-22-2009, 01:51 PM
Hello DJ


Sort off... i have got it working now, i ran a SQL statement on myphpadmin and then copied the php code and jiggled it here and there and it worked....

www.air-cargo-co2.com/index.php

So if you enter LHR to JFK it will calculate.

I do have another question..... not sure how to do the next part.

I have a second page linked to the tool which shows all the Departures/Arrivals (lanes). I want to be able to do the following.

www.air-cargo-co2.com/lanes.php

If i have a form and the user types Amsterdam is there away of scrolling the data to the top and change the colour of the fonts??

davidj
03-22-2009, 02:26 PM
so you dont want to sort the data at the SQL return point

you just want to scroll down to where the record exists in the recordset

cocoonfx
03-22-2009, 02:31 PM
Yep thats it, and change the font colour, would this be a java script or could this be done in PHP???

davidj
03-22-2009, 04:47 PM
you can set a CSS class to high lite the row and do the font change

you can also set an anchor in each row of the dynamic table and then redirect to the page with the results appending the anchor ref to the URL. This will not scroll animated like but will open the page and instantly scroll to the location

You could adapt this example if you want to see the scroll happen

http://www.issuetrackerproduct.com/About/#introduction

I'm sure you can adapt that example using PHP to send it the parameters