这是我的验证页面
<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/