if(!isset($_POST["user"]) 被忽略并返回未定义索引

发布于 11-02 04:47 字数 1224 浏览 5 评论 0 原文

当我输出这段代码时,

23  if(!isset($_POST['user'])) {
24    $user = $_POST['user'];
25    $user2 = $user;
26    $pass[0] = $_POST['password'];
27    $pass[1] = $_POST['password2'];
28    $email[0] = $_POST['email'];
29    $email[1] = $_POST['email2'];
30    $agree = $_POST['agreed'];
31    $reprint['user'] = $user;
32    $reprint['password'] = $pass[0];
33    $reprint['email'] = $email[0];
34    $reprint['agree'] = $agree;

它返回

Notice: Undefined index: user in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 24
Notice: Undefined index: password in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 26
Notice: Undefined index: password2 in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 27
Notice: Undefined index: email in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 28
Notice: Undefined index: email2 in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 29

Note,第23行没有错误,所以isset()总是返回true;当我的所有 $_POST[] 实际设置时,我没有收到任何错误。您可能无法重现此内容;可能只有 EasyPHP。我现在使用的是最新的 EasyPHP,PHP 5.3.6 VC9。我一直对 EasyPHP 的所有版本都遇到这个问题...所以我不确定是否有“更好”的语法或防止 EasyPHP 显示这些错误的方法。

When I output this code,

23  if(!isset($_POST['user'])) {
24    $user = $_POST['user'];
25    $user2 = $user;
26    $pass[0] = $_POST['password'];
27    $pass[1] = $_POST['password2'];
28    $email[0] = $_POST['email'];
29    $email[1] = $_POST['email2'];
30    $agree = $_POST['agreed'];
31    $reprint['user'] = $user;
32    $reprint['password'] = $pass[0];
33    $reprint['email'] = $email[0];
34    $reprint['agree'] = $agree;

it returns

Notice: Undefined index: user in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 24
Notice: Undefined index: password in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 26
Notice: Undefined index: password2 in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 27
Notice: Undefined index: email in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 28
Notice: Undefined index: email2 in C:\Program Files\EasyPHP-5.3.6.0\www\Arena\create_account.inc on line 29

Note that there is no error for line 23, so isset() always returns true; I don't get any error when all my $_POST[] are actually set. You might not be able to reproduce this; it may be only EasyPHP. I'm on the latest EasyPHP right now, with PHP 5.3.6 VC9. I've always had this problem with all versions of EasyPHP... So I'm not sure if there is a "better" syntax or a way to prevent EasyPHP from displaying these errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

俏︾媚 2024-11-09 04:47:54

您说的是$_POST['user'] 是否已设置。尝试删除否定运算符 !

// if user key has *not* been set
if(!isset($_POST['user'])) {
    $user = $_POST['user']; // undefined index because there is no 'user' key


if(isset($_POST['user'])) {
    $user = $_POST['user']; // no problems here

You are saying if $_POST['user'] has not been set. Try removing the negation operator !.

// if user key has *not* been set
if(!isset($_POST['user'])) {
    $user = $_POST['user']; // undefined index because there is no 'user' key


if(isset($_POST['user'])) {
    $user = $_POST['user']; // no problems here
静谧 2024-11-09 04:47:54

您尝试过吗:

if (isset($_POST['user'])) {

!isset 表示是否未设置。

Did you try:

if (isset($_POST['user'])) {

The !isset means if it is not set.

你又不是我 2024-11-09 04:47:54

如果设置了变量,isset() 返回 true;如果未设置,则返回 false。当前逻辑仅在 $_POST['user'] 未设置时执行。这是故意的吗?

在我看来,你需要删除你的 not 运算符。

isset() returns true if a variable is set and false if it is not. THe current logic only executes if $_POST['user'] is NOT set. Is this intentional?

It seems to me you need to remove your not operator.

风吹过旳痕迹 2024-11-09 04:47:54
error_reporting(E_ALL ^ E_NOTICE);

:)

我认为你应该将 isset 更改为 !empty...

!empty($_POST["user"])
error_reporting(E_ALL ^ E_NOTICE);

:)

I think you should change isset to !empty...

!empty($_POST["user"])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文