php html复选框错误
有人能告诉我为什么部分代码没有显示吗 这是我的HTML表单:php html复选框错误,php,html,Php,Html,有人能告诉我为什么部分代码没有显示吗 这是我的HTML表单: <form action="OrderOutput.php" method="Post"> <fieldset> <legend>Select a Crust</legend> <table> <tr> <td> <input type="radio" name="choice" value="Thin">Thin </td&
<form action="OrderOutput.php" method="Post">
<fieldset>
<legend>Select a Crust</legend>
<table>
<tr>
<td>
<input type="radio" name="choice" value="Thin">Thin
</td>
<td>
$1.00
</td>
</tr>
<tr>
<td>
<input type="radio" name="choice" value="Medium">Medium
</td>
<td>
$2.00
</td>
</tr>
<tr>
<td>
<input type="radio" name="choice" value="Thick">Thick
</td>
<td>
$3.00
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Select Toppings</legend>
<table>
<tr>
<td>
<input type="checkbox" name="check[]" value="Mushrooms">Mushrooms
</td>
<td>
$4.00
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="check[]" value="Pepperoni">Pepperoni
</td>
<td>
$5.00
</td>
</tr>
</table>
</fieldset>
<input type="submit" name="checkout" value="Checkout">
</form>
但不是这个:
foreach ($_POST['check'] as $selected_toppings) {
echo "Toppings: $selected_toppings ";
}
我的html复选框是否有问题导致信息无法在php中显示 您的代码工作正常,如果用户未提交任何复选框,您只需捕获:
if ( isset($_POST['check']) && is_array($_POST['check']) )
{
//If you want to just show toppings once, a simple implode will work:
//echo "Toppings: ", implode(', ', $selected_toppings);
foreach ($_POST['check'] as $selected_toppings) {
echo "Toppings: $selected_toppings ";
}
}
else
{
echo "Toppings: You didn't select any!";
}
将您的姓名更改为choice1、choice2和choice3,然后重试(并按原样检查$u POST['choice1']etcWorks。对您来说会发生什么?这是所有的代码吗?是错误还是只是没有显示浇头?您不需要在@user3791775执行此操作。您可以执行
打印($u POST)吗
并发布您看到的内容?提交前是否选中了一个框?没有显示浇头。这是我唯一的问题。请将给出问题的代码块注释掉,然后添加打印($\u post['check'])
它显示了什么?如果我不想使用foreach循环,我会做什么更改?如果两者都是chosenI,我不想显示两次浇头(在foreach循环上方)
if ( isset($_POST['check']) && is_array($_POST['check']) )
{
//If you want to just show toppings once, a simple implode will work:
//echo "Toppings: ", implode(', ', $selected_toppings);
foreach ($_POST['check'] as $selected_toppings) {
echo "Toppings: $selected_toppings ";
}
}
else
{
echo "Toppings: You didn't select any!";
}