我想要做的事情的基礎是檢查用戶值。爲什麼php跳過if語句?
如果他們在那裏返回true
並返回到頁面,否則返回false
並打印空值。
$query = sprintf("SELECT * from Users where username = ? and password = ?");
$params1 = array($username, $password);
$stmt = sqlsrv_query($conn, $query, $params1);
if ($stmt === false)
{
die(print_r(sqlsrv_errors(), true));
}
$Users = array();
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$username1 = $row['username'];
$password1= $row['password'];
}
$Users["username"] = $username1;
$Users["password"] = $password1;
//echo json_encode($Users);
echo "you are here";
if ($username1==null)
{
return false;
echo "null values";
}
else {
return true;
if (!empty($_SERVER['HTTP_REFERER']))
header("Location: ".$_SERVER['HTTP_REFERER']);
else
echo "No referrer.";
}
echo "\n\nyou're at the end though";
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
}
else {
echo "Connection could not be established.<br />";
die(print_r(sqlsrv_errors(), true));
}
正如你所看到的,我試圖調試程序,看看程序在哪裏。它得到的地步
//echo json_encode($Users);
echo "you are here";
之後沒有別的似乎工作,我不知道爲什麼。
虛假的東西,爲什麼你使用'前'返回false ; if塊中的''或''true''? – jmattheis
幫你一個忙,並設置xdebug,然後通過你的代碼。 echo或var_dump驅動的調試會讓人厭倦,並且會因爲不必要的語句而弄亂代碼庫。 – k0pernikus