update total price based on selection mysql php
Hello I hope someone can help me. I need to know how to write a query which will allow me to add a value based on fuel quantity selection.
For example say user sel开发者_如何学JAVAects 100 litres then add £5 to total or if they select 500 litres then add £15 etc.
Here is the code i currently have for calculating price per litre.
// show price
$fuelPriceQuery = sprintf("SELECT `Price` FROM fuel_price WHERE FuelType = '%s' LIMIT 1",
mysql_real_escape_string($_POST['fueltype']));
$fuelPriceResult = mysql_query($fuelPriceQuery);
$price = mysql_fetch_array($fuelPriceResult, MYSQLI_ASSOC);
echo 'The Price Today is £'.($_POST['qtylitres'] * $price['Price']);
echo "<br />";
echo "For " . ($_POST['qtylitres']) . " Litres of " .($_POST['fueltype']);
echo "<br />" . "<br />";
if(mysql_num_rows(mysql_query("SELECT * FROM subscribe WHERE Email = '".mysql_real_escape_string($_POST['inputEmail'])."'")))
{
echo "Thanks but we already have your email";
}
else
{
Extend your Code by this snippet, if i understand you right it should do exactly what you wanted.
[...]
if($_POST['qtylitres'] >= 100)
$fee = 5;
if($_POST['qtylitres'] >= 500)
$fee = 15;
echo 'The Price Today is £'.(($_POST['qtylitres'] * $price['Price'])+$fee);
[...]
精彩评论