简体   繁体   中英

PHP: adding prices to a form

I am trying to edit my PHP script so the prices I have added to the form will be added as a total when the user clicks submit but I am not sure how to add up the values.

HTML

<select name="service">
<option value="Yes" value="10">Yes £10</option>
<option value="No">No</option>
</select>

<form method="post" action="example.php">
<select name="booking">
<option value="Double Room" value="50">Double Room £50</option>
<option value="Twin Room" value="70">Twin Room £70</option>
<option value="Family Room" value="100">Family room £100</option>
</select>
<br /> <br />
<input type="submit" value="submit" action="example.php" name="submit"><br />
</form>

PHP

You have choosen the <?php echo $_POST["booking"]; ?>

You're defined twice the value attribute of the options tags and this is an error .

If you want to access the price, just set the price as a single value attribute.

A better way would be to identify each row with an ID and having a corresponding array in PHP to get both the name and the price (either as an array again, or better as an object).

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM