这是我的验证页面
<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>
>
我无法从数据库中获取数据,它向我显示错误。我认为我在向SQL查询声明会话变量时犯了错误
答案 0 :(得分:2)
你的sql上有错误。
$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email=".$_SESSION['email']);
应该是:
$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email='".$_SESSION['email']."');
答案 1 :(得分:0)
注释行检查时出错。
$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email='".$_SESSION['email']."'"); // this line has an issue with "'"
<html>
<body>
<?php
require_once 'valid.php';
session_start();
echo"welcome " .$_SESSION['email'];
$res=mysqli_query($conn,"SELECT * FROM MyGuests WHERE email='".$_SESSION['email']."'"); // Missing "'" in query to enclosed parameter.
$userRow=mysqli_fetch_array($res);
echo $userRow;
?>
<br><a href="logout.php">logout</a>
</body>
</html>