Php 下面的代码给出了解析错误:语法错误,意外的T_变量
下面的代码给出了Php 下面的代码给出了解析错误:语法错误,意外的T_变量,php,Php,下面的代码给出了解析错误:语法错误,意外的T_变量。在第8行 <?php session_start(); $email=$_REQUEST['email']; $password=$_REQUEST['password']; $con=mysqli_connect("localhost","root","","mydb"); if(mysqli_fetch_array(mysqli_query($con,"select*from user10
解析错误:语法错误,意外的T_变量。在第8行
<?php
session_start();
$email=$_REQUEST['email'];
$password=$_REQUEST['password'];
$con=mysqli_connect("localhost","root","","mydb");
if(mysqli_fetch_array(mysqli_query($con,"select*from user101 where
email="$email" and password="$password"")))
{
$_SESSION['email']=$email;
echo "login successful";
header("Location:welcome.php");
}
else
{
echo "Login failed";
}
?>
试试这个,因为你有很多双引号,这是错误的。它应该是这样的“'var''var'”
您可以在sqlstring中编写单引号,从而解决了此问题。但我建议使用mysql转义函数来防止sql注入
<?php
session_start();
$email=$_REQUEST['email'];
$password=$_REQUEST['password'];
$con=mysqli_connect("localhost","root","","mydb");
if(mysqli_fetch_array(mysqli_query($con,"select*from user101 where
email='$email' and password='$password'")))
{
$_SESSION['email']=$email;
echo "login successful";
header("Location:welcome.php");
}
else
{
echo "Login failed";
}
将您的线路号8替换为此-
if(mysqli_fetch_array(mysqli_query($con,"select * from user101 where
email='$email' and password= '$password'")))
我希望这对你有帮助 可能是这样的。在外部使用双引号时,避免在查询内部使用双引号
mysqli_query($con,"select*from user101 where
email='$email' and password='$password'")
警告:您的代码对SQL注入非常开放,您应该使用准备好的语句,而不是像这样连接查询。切勿以纯文本形式存储密码。仅存储哈希密码。使用password\u hash()
和password\u verify()
。另外,在设置标题之前,您不能有echo
。标题必须位于任何输出之前。在重定向用户之前回显某个内容实际上没有任何意义,因为用户将无法看到它。如果您接受其中一个答案并标记有用的注释,那就太好了
mysqli_query($con,"select*from user101 where
email='$email' and password='$password'")