我正在尝试创建一个简单的购物车。这允许用户使用<select>
标签从下拉菜单中选择数量。默认情况下,除非选择数量,否则它显示为“ 1”,请参见下文:
问题:单击更新并更新购物车后,我得到一个“ <”符号。
我无法弄清楚为什么我得到“ <”符号,我的<select>
标签和value
属性看起来正确吗?
这是我的代码:
// If the update button is clicked and the if an option has been selected for the <select> tag.
if(isset($_POST['updated_value'])) {
if(isset($_POST['selectDropDown'])) {
$updatedValue = $_POST['selectDropDown'];
}
} else {
$updatedValue = '1';
}
?>
<table>
<tr>
<th>Description </th>
<th>Quantity</th>
</tr>
</table>
<?php while($cart = mysqli_fetch_assoc($result)) { ?>
<form action="cart.php" method="POST">
<table>
<tr>
<td>
<?php echo $cart["prod_desc"]; ?>
</td>
<td>
<select name= "selectDropDown" >
<option value=< <?php echo $updatedValue; ?> > <?php echo $updatedValue; ?> </option>
<option value=<2> 2 </option>
<option value=<3> 3 </option>
<option value=<4> 4 </option>
<option value=<5> 5 </option>
<option value=<6> 6 </option>
<option value=<7> 7 </option>
<option value=<8> 8 </option>
<option value=<9> 9 </option>
<option value=<10> 10 </option>
</select>
</td>
<td>
<input type="submit" name="updated_value" value="update"/>
</td>
</tr>
</table>
</form>
<?php
}
?>
有任何想法吗?请帮忙!
试试这个,
// If the update button is clicked and the if an option has been selected for the <select> tag.
if(isset($_POST['updated_value'])) {
if(isset($_POST['selectDropDown'])) {
$updatedValue = $_POST['selectDropDown'];
}
} else {
$updatedValue = '1';
}
?>
<table>
<tr>
<th>Description </th>
<th>Quantity</th>
</tr>
</table>
<?php while($cart = mysqli_fetch_assoc($result)) { ?>
<form action="cart.php" method="POST">
<table>
<tr>
<td>
<?php echo $cart["prod_desc"]; ?>
</td>
<td>
<select name= "selectDropDown" >
<option value="<?php echo $updatedValue; ?>" > <?php echo $updatedValue; ?> </option>
<option value=2> 2 </option>
<option value=3> 3 </option>
<option value=4> 4 </option>
<option value=5> 5 </option>
<option value=6> 6 </option>
<option value=7> 7 </option>
<option value=8> 8 </option>
<option value=9> 9 </option>
<option value=10> 10 </option>
</select>
</td>
<td>
<input type="submit" name="updated_value" value="update"/>
</td>
</tr>
</table>
</form>
<?php
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句