gpt4 book ai didi

php - 无法从 MySQL 获取数据

转载 作者:行者123 更新时间:2023-11-29 06:50:42 25 4
gpt4 key购买 nike

这是我的验证页面

 <html>
<body>
<?php
function error_found(){
header("Location: login.php");
}
set_error_handler('error_found');
?>
<?php
$con=mysqli_connect('localhost','root','','mydb');
session_start();
if(isset($_POST['loginbtn'])){
$email=$_POST['email'];
$password=$_POST['pwd'];
$result=mysqli_query($con,'select * from myguests where email="'.$email.'" and password="'.$password.'"');
if(mysqli_num_rows($result)==1)
{
$_SESSION['email']= $email;
header("Location: welcome.php");
}
else
echo"INVALID ACCOUNT";

}

?>

</body>
</html>

这是我的用户个人资料页面

<html>
<body>

<?php
require_once 'valid.php';
session_start();
echo"welcome " .$_SESSION['email'];
$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email=".$_SESSION['email']);
$userRow=mysqli_fetch_array($res);
echo $userRow;
?>
<br><a href="logout.php">logout</a>
</body>
</html>

>

I am not able to fetch the data from the database it shows me the error.I think I made mistake in declaring a session variable to the SQL query

最佳答案

您的 sql 有错误。

$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email=".$_SESSION['email']);

应该是:

$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email='".$_SESSION['email']."');

关于php - 无法从 MySQL 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47646788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com