未定义的索引如果我不检查复选框 [英] Undefined Index If I Do Not Check Checkbox

查看:107
本文介绍了未定义的索引如果我不检查复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在这里发生了一件奇怪的事情。
如果我检查表单上的复选框,那么php脚本完美运行。
如果我没有选择框,php会报告另一个变量的未定义索引。
$ b

这是使用IIS本地主机检查的。



在网络上发布的相同脚本无论如何都可以工作。
那么,几乎相同。我在本地添加了一个变量'test'POST到PHP并与硬编码值进行比较。这就是全部。



以下是复选框的html:

 < ; TR> 
< td>发布评论?< / td>
< td>< input name =publishokvalue =NOtype =checkbox>复选框对于做spanstyle =font-weight:bold;>不是< / span>发布和LT; / TD>
< / tr>
< tr>

以下是变量'publishok'的php:

  $ IP = $ _SERVER [REMOTE_ADDR]; 
$ publishok = $ _POST ['publishok'];
$ test = $ _POST ['test'];
if($ test!='park')die(输入错误,对不起,回去再试一次);

我怀疑我的编辑器PSPad正在添加虚假(和不可见)char代码或其他东西,所以我升级到最新版本。没有区别。



不能认为可能导致这种情况。



任何人都可以提供帮助吗?

解决方案

复选框不会发送数据到服务器,当你没有检查它。



您必须使用 isset($ _ POST ['publishok'])检查它是否在服务器端进行检查。


I seem to have a bizarre happening here. If I check a checkbox on the form then the php script runs perfectly. If I don't check the box php reports an undefined index on another variable.

That's using IIS localhost, checking things.

On the web the published identical script works no matter what. Well, virtually identical. I have locally added a variable 'test' POST-ed to php and compared with a hard coded value. That's all.

Here's the html for the checkbox:

<tr>
<td>Publish Comment?</td>
<td><input name="publishok" value="NO" type="checkbox"> Check Box For Do spanstyle="font-weight: bold;">Not</span> Publish</td>
</tr>
<tr>

and here's the php for the variable, 'publishok' :

$IP = $_SERVER["REMOTE_ADDR"];
$publishok = $_POST['publishok'];
$test = $_POST['test'];
if ($test != 'park') die ("Wrong input. Sorry. Go back, try again"); 

I suspected my editor PSPad was adding spurious (and invisible) char codes or something so I upgraded to the latest version. No difference.

Can't think what could cause this.

Can anyone help?

解决方案

checkbox won't send the data to the server when you did not check it.

You have to use isset($_POST['publishok']) to check it whether it is checked in the server side.

这篇关于未定义的索引如果我不检查复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆