以下代码给出了Parse错误:语法错误,意外的T_VARIABLE

时间:2018-05-04 07:16:27

标签: php

以下代码为Parse error: syntax error, unexpected T_VARIABLE. on line 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";
    }
?>

4 个答案:

答案 0 :(得分:1)

试试这个,因为你有很多双引号,这是错误的。它应该是这样的''var''var'“

<?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";
}
?>

答案 1 :(得分:0)

你可以用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";
}

答案 2 :(得分:0)

将此行号8替换为 -

if(mysqli_fetch_array(mysqli_query($con,"select * from user101 where 
email='$email' and password= '$password'")))

我希望这会对你有所帮助!

答案 3 :(得分:0)

可能是这样的。在外部使用双引号时,避免在查询中使用双引号

mysqli_query($con,"select*from user101 where 
email='$email' and password='$password'")