显示这句话 Call to undefined method mysqli_result::fetch_all() in /home/u852222608/public_html/message.php下面是代码:
<?php
ob_start();
session_start();
$username = $_POST["username"];
$password = $_POST["password"];
$mysql = new mysqli("127.0.0.1:8889","root","123456","myPhp");
$a = $mysql->query("set names utf8");
if ($a) {
$result = $mysql->query("select password from user where name = '$username'");
if ($result->num_rows) {
# code...
$array = $result->fetch_all(MYSQLI_ASSOC);
foreach ($array as $value) {
# code...
if ($password == $value["password"]) {
# code...
$_SESSION["username"] = $username;
echo "<script>alert('登录成功');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
}else{
echo "<script>alert('密码不正确或不能为空');history.go(-1)</script>";
}
}
}else{
echo "<script>alert('用户名不能为空或注册后再登录');history.go(-1)</script>";
}
}else{
echo "<script>alert('用户名不能为空或密码');history.go(-1)</script>";
}
?>
<?php
ob_start();
session_start();
$username = $_POST["username"];
$password = $_POST["password"];
$mysql = new mysqli("127.0.0.1:8889","root","123456","myPhp");
$a = $mysql->query("set names utf8");
if ($a) {
$result = $mysql->query("select password from user where name = '$username'");
if ($result->num_rows) {
# code...
$array = $result->fetch_all(MYSQLI_ASSOC);
foreach ($array as $value) {
# code...
if ($password == $value["password"]) {
# code...
$_SESSION["username"] = $username;
echo "<script>alert('登录成功');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
}else{
echo "<script>alert('密码不正确或不能为空');history.go(-1)</script>";
}
}
}else{
echo "<script>alert('用户名不能为空或注册后再登录');history.go(-1)</script>";
}
}else{
echo "<script>alert('用户名不能为空或密码');history.go(-1)</script>";
}
?>
换成
select * from user where name = '$username 看看
另外,代码的逻辑有些问题。