duanhao4909
duanhao4909
2018-05-04 07:16
浏览 66
已采纳

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

The following code gives 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条回答 默认 最新

  • dougutuo9879
    dougutuo9879 2018-05-04 07:20
    已采纳

    Try this because you had many double quotes and that is wrong.It should be like this " '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";
    }
    ?>
    
    点赞 评论
  • drwxg62286
    drwxg62286 2018-05-04 07:20

    you can write single quote in sqlstring solved this problem. But i suggest use mysql escape functions for prevent sql injections

    <?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";
    }
    
    点赞 评论
  • dousha1394
    dousha1394 2018-05-04 07:22

    Replace your line number 8 with this -

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

    I hope this will help you!

    点赞 评论
  • doujiaozhan4397
    doujiaozhan4397 2018-05-04 07:22

    It could be like this. avoid double quote inside the query when using double quote in outside

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

相关推荐