开发者

php mysql Calculate price from database value with form selection

Hello I am really struggling with this. I was asked to develop a script to calculate oil price but cannot get it to work. I have been able to setup a form to update fuel price.

I have a table called fuel_price. In this table wi开发者_如何学运维ll be cost per litre of fuel which is stored under fueltype.

For example there are Four columns in the table ‘ID’ value=1, ‘Oil’ value= £0.50, ‘Diesel’ value=£0.85 and RedDiesel value=’£0.75’.

I need to multiply selected fuel type by quantity of litres selected within form. Can anyone please guide me on what I am supposed to do??

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<select name="fueltype">
<option>- Select fuel type -</option>
<option value="Diesel">Diesel</option>
<option value="Red Diesel">Red Diesel</option>
<option value="Home Heating Oil">Home Heating Oil</option>
</select>
<select name="qtylitres">
<option>- Qty in Litres -</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="400">400</option>
<option value="500">500</option>
<option value="900">900</option>
<option value="1000">1000</option>
</select>

<input type="hidden" name="id" value="" />
<input type="submit" name="submit" value="Submit" />
</form>

<?php

include 'mysql_connect.php';

    $stmt = $pdo->prepare("SELECT `Oil` from `fuel_price` WHERE id = '1'"); 
    if (!$stmt->execute()) { die($stmt->errorInfo[2]); } 
    $row = $stmt->fetch(); 

    $price = $row['Oil'];

    echo $_POST['qtylitres'] * $price; 

?>

Please help really unsure what to do??


maybe by putting

global $pdo;

in both mysql_connect.php and your file, just after the include statement will solve your issue

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜