2017-08-10 150 views
1

这是我的HAUNTED代码。更改变量

ini_set("display_errors", true); 
ini_set("html_errors", false); 
require "conn.php"; 
echo "debug 1"; 
$stmt2 = $conn->prepare("SELECT * FROM UserData WHERE username = ?"); 
$stmt2->bind_param('s',$username); 
//$username = $_POST["username"]; 
$username ="netsgets"; 
$stmt2->execute(); 
$stmt2->store_result(); 
if ($stmt2->num_rows == 0){ // username not taken 
echo "debug 2.5"; 

die; 
}else{ 
// prepare query 
$stmt=$conn->prepare("SELECT * FROM UserData WHERE username = ?"); 
// You only need to call bind_param once 
$stmt->bind_param('s',$username); 
$username = "netsgets"; 
// execute query 
$stmt->execute(); 
$stmt->store_result(); 
// bind variables to result 
$stmt->bind_result($id,$dbUser,$dbPassword,$Type1,$Type2,$Type3,$Type4,$Type5); 
//fetch the first result row, this pumps the result values in the bound variables 

if($stmt->fetch()){ 
    echo 'result is ' . $Type1, $Type2,$Type3,$Type4,$Type5; 
} 


//var_dump($query2); 
echo "hi"; 

echo "debug 2"; 



echo "debug 2.7"; 

    if ($Type1 == "empty"){ 

     echo "debug 3"; 
     $sql11 = $conn->prepare("UPDATE UserData SET likedOne=? WHERE username=?"); 
     $sql11->bind_param('ss',$TUsername,$Username); 
//  $TUsername = $_POST["TUsername"]; 
//  $Username = $_POST["username"]; 
     $TUsername = "test"; 
     $Username = "netsgets"; 
     $sql11->execute(); 



    } 
} 

这就是它返回的结果(回声)。

Connected successfullydebug 1result is empty empty empty empty empty hidebug 2debug 2.7 

正如您所见,变量Type1,Type2,Type3,Type4,Type5都等于“空”。 由于某些原因,正如你所看到的,if语句不认为它是“空的”,因为它没有回显“debug 3”。什么.....(也没有错误。)

+0

您还没有在任何地方声明$ Type1等。 – Difster

+1

$ stmt-> bind_result($ id,$ dbUser,$ dbPassword,$ Type1,$ Type2,$ Type3,$ Type4,$ Type5); –

+0

难道不是吗? –

回答

1

如果此代码...

echo 'result is ' . $Type1, $Type2,$Type3,$Type4,$Type5; 

字面上产生这样的输出...

结果为空空空空空

与之间的每一个“空”的空间,那么显然在数据库中Type*值都是"empty "" empty"或索姆与前导/尾随空白相结合的其他组合。

你会想要做的比较

trim($Type1) == 'empty' 

此外,如在评论中提到,在组合从未使用SELECT *bind_result。您应该始终明确所选择的列以及它们出现的顺序,例如

SELECT id, dbUser, dbPassword, Type1, Type2, Type3, Type4, Type5 FROM ... 
+0

谢谢菲尔。 –

+0

顺便说一句,它仍然适用于'SELECT *' –

+0

当然,直到您添加或删除列或您的数据库决定更改订单 – Phil