首先,我知道我在 php 开发方面非常糟糕,但我尽力了 :) 我有 2 个选择字段,如果项目二和选项 1 都被选中,我想在 $price2 上加 10。所以我尝试了这个:
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
items:<br>
<select name="test[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
</select><br>
options:<br>
<select name="options" class="quoteFields" tabindex="5" size="1">
<option value="0" selected="selected">Choose an option</option>
<option value="option1">option1</option>
<option value="option2">option2</option>
</select> <br>
<input type="submit" value="Send" />
</form>
<?php
$test=$_POST['test'];
if ($test){
foreach ($test as $t){
echo 'You selected ',$t,'<br />';
if($t=='one')
$price1=12;
if($t=='two')
$price2=2;
}
}
if ($_POST['test'] === 'two') {
switch ($options){
case "option1":
$price2 = $price2 + 10;
break;
}
}
$total = $price1 + $price2;
echo $total;
?>
但它不起作用,有人可以帮忙吗?