我在这里找不到你的帮助?这是我的错误
致命错误:在
中调用未定义的方法mysqli :: bind_param()
我不知道出了什么问题
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST))
{
$login = $_POST['login'];
$password = $_POST['password'];
$email = $_POST['email'];
if(empty($login) || empty($password) || empty($email))
{
die('Comeplete all text.');
}
elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
die('Nie poprawny adres E-mail.');
}
else
{
include_once('config.php');
$mysqli = new mysqli('****', '******', '*****') or die ('Fatal Error: '.mysql_error());
if($mysqli -> connect_error)
die('Error Connection:'.$mysqli -> connect_error.'['.$mysqli -> connect_errno.']');
$login = trim(htmlspecialchars($mysqli -> real_escape_string($login)));
$password = hash('sha256', trim(htmlspecialchars($mysqli -> real_escape_string($password))));
$email = trim(htmlspecialchars($mysqli -> real_escape_string($email)));
$ip = $_SERVER['REMOTE_ADDR'];
$stmt = $mysqli -> prepare("INSERT INTO `user`(`id_user`, `login`,`password`,`email`,`added`,`ip`) VALUES('', ? , ? , ? , now(), ?)");
$stmt = $mysqli -> bind_param("ssss", $login, $password, $email, $ip);
if ($stmt) {
$stmt->execute();
echo 'Success';
}
}
}
?>
</section>
</body>
</html>
答案 0 :(得分:4)
问题是,你在MySQL上使用bind_param
函数而不是$stmt
变量。
问题出在这一行:
$stmt = $mysqli -> prepare("INSERT INTO `user`(`id_user`, `login`,`password`,`email`,`added`,`ip`) VALUES('', ? , ? , ? , now(), ?)");
$stmt = $mysqli -> bind_param("ssss", $login, $password, $email, $ip);
而不是输入:
$stmt = $mysqli->bind_param("ssss", $login, $password, $email, $ip);
您应该输入:
$stmt = $stmt->bind_param("ssss", $login, $password, $email, $ip);
由于bind_param
方法仅适用于mysqli_stmt
类。而不是mysqli
。
查看文档here。
答案 1 :(得分:2)
bind_param
是mysqli_stmt
的方法,而非mysqli
。它应该是:
$stmt->bind_param("ssss", $login, $password, $email, $ip);
答案 2 :(得分:0)
我纠正了。没有任何改变
value