$_POST 未设置
有谁知道为什么 $_POST
没有被设置?
这是一些代码。
<form method="post" name="form" id="clientForm" action="">
<input type="submit" name="sub" value="Delete_Checked"/>
<?php if ($i%2){ ?> class="even"<?php } ?>
<input type="checkbox" name="doc[]" value="<?php echo $document->doID; ?>"/>
<?php $i++; } ?>
</form>
<?php
if (isset($_POST['sub']) == 'Delete_Checked'){
print_r($_POST['sub']); // nothing gets print.......
}
?>
我一定是忽略了什么。
does anyone have any idea why $_POST
not being set??
here is some of the code.
<form method="post" name="form" id="clientForm" action="">
<input type="submit" name="sub" value="Delete_Checked"/>
<?php if ($i%2){ ?> class="even"<?php } ?>
<input type="checkbox" name="doc[]" value="<?php echo $document->doID; ?>"/>
<?php $i++; } ?>
</form>
<?php
if (isset($_POST['sub']) == 'Delete_Checked'){
print_r($_POST['sub']); // nothing gets print.......
}
?>
i must be overlooking something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果提交时未选中该复选框,则该复选框不会出现在 $_POST 数组中。
$_POST 本身总是被设置的。当您需要查看其中包含的所有内容时,请尝试此操作:
确保您也使用“post”作为表单方法。
此外,当您的代码仅显示 'doc[]` 输入时,您似乎正在尝试访问
$_POST['sub']
。If the checkbox is not checked when submitted, it won't be in the $_POST array.
$_POST itself is always set. Try this instead when you need to see everything it contains:
Make sure you are using "post" as your form method as well.
Also, you seem to be trying to access
$_POST['sub']
when your code only shows the 'doc[]` input.不应该这样写。它只会在偶然情况下起作用。
作者想写的是:
我个人会省略整个
isset
部分,因为这正是阻碍您评估原因的原因。This is not how it should be written. It will only work by accident.
What the author wanted to write was:
I would personally leave out the whole
isset
part, because that's exactly what's obstructing your assessment of the cause.该输入应该在带有 POST 方法的表单内
<代码>
尝试将操作放入
action=""
that input should be inside form with method POST
try to put the action to
action="<?php echo $_SERVER['PHP_SELF'];?>"