所以我试图在函数内部运行一个预处理语句,但似乎很难通过mysqli连接语句。我现在肯定超过了100次尝试组合......
在函数中使用之前,我将连接用于另一个预准备语句。由于难以将include()传递给函数
,我甚至在语句中声明了我的连接变量include('phpsqlinfo_dbinfo.php');
$mysqli = new mysqli($host, $dbusername, $dbpassword, $database);
$stmt = $mysqli->prepare("SELECT id, email, username, password, gender, homelat")
//blah blah blah run a statement here. I omitted this statement for brevity purposes.
$stmt->close();
$mysqli->close();
function storeTokenForUser($username,$token) {
echo "running2";
echo $token;
echo $username;
$host="";
$dbusername="XXXX";
$dbpassword="XXXX";
$database="XXXX";
global $mysqli;
$stmt=$mysqli->prepare("INSERT INTO cookielogin (username, token) VALUES (?,?)");
$stmt->bind_param('ss', $username, $token1);
$stmt->execute();
if (mysqli_connect_errno()) {
echo("error".htmlspecialchars($mysqli->error).htmlspecialchars($stmt1->error));
}
echo"running3";
}
function cookie($username,$mysqli) {
$token = md5(uniqid(mt_rand(), true));
storeTokenForUser($username, $token);
$cookie = $username . ':' . $token;
$mac = hash_hmac('sha256', $cookie, 9842);
$cookie .= ':' . $mac;
setcookie('rememberme', $cookie);
echo"running1";
}
在我的努力中,我遇到了不同的错误,但是现在,这给了我:
Warning: mysqli::prepare(): Couldn't fetch mysqli in /var/www/loginphp.php on line 63
Fatal error: Call to a member function bind_param() on a non-object in /var/www/loginphp.php on line 64
真诚地感谢您的帮助。非常感谢。
答案 0 :(得分:2)
卸下:
$stmt->close();
$mysqli->close();
修复错误并:
$stmt->bind_param('ss', $username, $token1);
$token1
未定义。