问题:我正在设置我的登录系统,它应该允许用户使用用户名或密码登录。但是我的准备语句返回Prepare failed: (0)到控制台(0 是 mysql 错误号)。
我试过的:我试过查看 MySQL 手册,看看是什么Error Number 0,但找不到任何东西。
<?php
include "../includes/config.php";
if($_SERVER["REQUEST_METHOD"] == "POST") {
// Can be either the email or username
$login = $_POST['login'];
$password = $_POST['password'];
if ( $login != "" && $password != "" ) {
// Prepare the statement
$pullLogin = $link->prepare("SELECT hashed_password FROM users WHERE (username = '?' OR email='?')");
// Check Prepare
if ( !$pullLogin->prepare() ) { echo "<script>console.log('Prepare failed: ($pullLogin->errno) $pullLogin->error');</script>"; }
// Bind the parameters to the statement
$pullLogin->bind_param( "ss", $login, $login );
// Execute it :-)
$pullLogin->execute();
// Store the results, I don't really knwo why but whatever
$pullLogin->store_result();
// Bind the password to a variable :-)
$pullLogin->bind_result($correctPassword);
// Free the results
$pullLogin->free_results();
// Close the statement
$pullLogin->close();
// This is hashed and I'm only echoing it to see if ^ works
echo $correctPassword;
}
}
?>
预期:用户可以使用他们的用户名或电子邮件登录。
实际结果:准备语句似乎不起作用:/
猛跑小猪