Hello I can’t get my script fully operational.
I have it calculating properly but now need a query for fuel type.
<?php
include 'mysql_connect.php';
$query = "SELECT * FROM fuel_price WHERE FuelType='Oil'" ;
$result = mysql_query($query);
$price= mysql_fetch_array($result);
if(isset($_POST['submit'])){
echo "The Price Today is ";
echo "£"; echo $_POST['qtylitres'] * $price ['Price'];
} else {
echo "Please select value";
}
?>
I need to to check fueltype selected on form and calculate total accordingly.
eg $query = “SELECT * FROM fuel_price WHERE FuelType='{$_POST[‘fueltype’];}'” ;
Please help anyone under pressure.
Thanks
A couple of things to note:
Always make sure to escape the user input by using
mysql_real_escape_string, if you are not using prepared statements such as PDO, MySQLi, etc…I added the
LIMITclause to the query somysql_fetch_arraywill work, because if it returns more than one row, then you would have to handle it in a loop.It is not necessary to use multiple
echos, in fact it is better if you use as few as possible.