出於某種原因,我的準備聲明似乎沒有返回任何行或登錄,但我確定輸入的密碼和用戶名是正確的;在沒有準備語句的情況下運行代碼時,系統會登錄。是否有人會知道我的準備語句不工作的原因,或者是否有其他方法可以使用?爲什麼我的準備聲明不起作用?
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<title>Logged in</title>
</head>
<body>
<?php
$user=$_GET["username"];
$pass=$_GET["password"];
$servername="localhost";
$username="root";
$password="";
$dbName="db_artzytest";
$conn=new mysqli($servername, $username, $password, $dbName);
if($conn->connect_error){
echo $conn->connect_error;
die("connection to server not found");
}else{
echo "connection established";
}
///finds account with matching login info
$sql="SELECT * FROM db_users WHERE username='{$user}' AND password='{$pass}' ";
$sql="SELECT * FROM db_users WHERE username = ? AND password = ?";
try{
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $user, $pass);
$stmt->execute();
}catch(Exception $e){
die("prepare failed: " . $e);
}
echo 'here';
//$result = $stmt->store_result();
printf("Number of rows: %d. \n", $stmt->num_rows);
//$result=$conn->query($sql);
echo 'here';
if(mysqli_num_rows($result) > 0){
while($row=mysqli_fetch_assoc($result)){
//only logs in if the account is activated
if($row["isActivated"]==1){
$_SESSION["currentUser"]=$user;
$_SESSION["currentId"]=$row["id"];
$_SESSION["currentPass"]=$pass;
//header('Location: ../ProfilePage/profilePage.php');
header('Location: ../Content/displayGroup.php?group=general');
}else{
$_SESSION["m_Login"]="Unverified Account. Check your email to verify.";
header('Location: Login.php');
}
}
/*
$sql=" SELECT * FROM table_images WHERE userid = {$_SESSION["currentId"]} ";
$result=$conn->query($sql);
if(mysqli_num_rows($result) > 0){
while($row=mysqli_fetch_assoc($result)){
echo "<img style='height: 10vh; width: 10vw;' src='../../images/{$row["id"]}.jpg' />";
echo "{$row["imageName"]}</br>";
}
}
*/
}else{
$_SESSION["m_Login"]="password or username incorrect {$user} {$pass}" . var_dump(mysqli_stmt_get_result($stmt));
header('Location: Login.php');
echo "no user found";
}
?>
</body>
</html>
Java在哪裏? – Script47
基本調試:確保'$ _GET'不是'$ _POST',並且數據正在傳遞。爲什麼你要定義'$ sql'並且立刻用問號參數重新定義它?總是在'header'中使用'exit'來防止錯誤。 – Script47