2011-04-16 52 views
2

當我輸出此代碼,

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 

注意,沒有錯誤第23行,因此isset()總是返回true;當我所有的$ _POST []都被設置時,我不會收到任何錯誤,您可能無法重現這一點;它可能只是EasyPHP。 EasyPHP,現在使用PHP 5.3.6 VC9,所有版本的EasyPHP都存在這個問題...所以我不確定是否有更好的語法或防止EasyPHP的方法從顯示這些錯誤。

回答

7

您是在說如果$_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 
+1

@Xifanie - 這一切都很好。你被困在一個愚蠢的理由。每天都會發生在每個人身上。 :) – karim79 2011-04-16 00:41:57

0

你嘗試!如果沒有設置

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

的isset手段。

0

isset()如果設置了變量則返回true,否則返回false。只有當$ _POST ['user']沒有被設置時,當前邏輯纔會執行。這是故意的嗎?

在我看來,你需要刪除你的不是運營商。

0
error_reporting(E_ALL^E_NOTICE); 

:)

我想你應該改變isset!empty ...

!empty($_POST["user"])