我正在使我的网站无法使注册部分工作,请帮助。
这些是我得到的错误:
致命错误:未捕获的错误:在第 43 行的 C:\wamp64\www\logins\login.php 中调用成员函数 bind_param()
和:
错误:在第 43 行调用 C:\wamp64\www\logins\login.php 中布尔值的成员函数 bind_param()。
这是我的登录文件代码:
<?php
require_once "../cookieSenders/sendLoginCookie.php";
require_once "../resources/ConnectToServer.php";
require_once "../resources/GenerateRandomString.php";
$login_type = $_GET["login_type"];
?>
<html>
<head>
<title>PatHTML
</title>
<link rel="shortcut icon" href="../favico.ico" />
</head>
<body>
<h1><?php echo $_GET["login_type"]; ?></h1>
<?php
if ($login_type == "login") { ?>
<form method="post">
</form>
<?php } elseif ($login_type == "signup") { ?>
<form method="post" action="">
<input type="email" name="gmail" placeholder="Type your EMAIL."></input>
<input type="text" name="username" placeholder="Type your USERNAME."></input>
<input type="password" name="password" placeholder="Type your PASSWORD."></input>
<input type="submit" value="Submit"></input>
<?php
$new_gmail ="";
$new_password ="";
$new_username ="";
if (isset($_POST['gmail'])) $new_gmail = $_POST['gmail'];
if (isset($_POST['username'])) $new_username = $_POST['username'];
if (isset($_POST['password'])) $new_encoded_password = password_hash($_POST['password'], PASSWORD_BCRYPT);
if (isset($new_encoded_password))
{
$sql = mysqli_query($conn, "INSERT INTO `users` (`username`,`password`,`email`, `LoginCookie`) VALUES (?,?,?,?)");
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssss", $new_username, $new_encoded_password, $new_gmail, GenerateRandomString());
$stmt->execute();
}
?>
</form>
<?php } else {
header("Location: ../error404.php?error=404&error_name=Login%20Type%20error&eBAT=$login_type");
exit();
}
?>
</body>
</html>
这是我的 ConnectToServer.php 脚本:
<?php
$sql_servername = "192.168.100.4";
$sql_username = "connect";
$sql_password = "LxcyXp12tclgU7dx";
$sql_database = "pathtml";
$conn = new mysqli($sql_servername, $sql_username, $sql_password);
mysqli_select_db($conn, $sql_database);
if (!$conn) die("Connection failed to server:" . mysqli_connect_error());
function CloseServerConnection()
{
if ($conn) {
mysqli_close($conn);
}
}
?>
如何将我的新用户写入数据库?
此语法不正确
$sql = mysqli_query($conn, "INSERT INTO `users`
(`username`,`password`,`email`, `LoginCookie`)
VALUES (?,?,?,?)");
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssss", $new_username, $new_encoded_password, $new_gmail, GenerateRandomString());
$stmt->execute();
}
您正在运行未准备好的查询,这永远不会起作用
我认为你提到的代码是
$sql = "INSERT INTO `users`
(`username`,`password`,`email`, `LoginCookie`)
VALUES (?,?,?,?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssss", $new_username, $new_encoded_password,
$new_gmail, GenerateRandomString());
$stmt->execute();
}
即使在 LIVE 环境中,要从 PHP 中获取错误,请将这 4 行添加到
MYSQLI_
您要调试的任何基于脚本的顶部
ini_set('display_errors', 1);
ini_set('log_errors',1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);`.
这将强制任何
MYSQLI_
错误生成一个您可以在浏览器上看到的异常以及正常的 PHP 错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句