-2

Code:

<?php 
session_start();
require "connect.inc.php";                           //如果提交表单就链接数据库验证
if(isset($_POST['sub']))
{
   // 使用从表单中接收到的用户名和密码,作为在user表中的查询条件
    $stmt = $pdo->prepare("SELECT id,username FROM user WHERE username=? and userpwd=?");
    $stmt->execute(
        array($_POST["username"],md5($_POST["password"]) )
    );

    if ($stmt->rowCount()>0) 
    {
        $_SESSION=$stmt->fetch(PDO::FETCH_ASSOC);   
        // 将用户信息注册进入session
        $_SESSION["isLogin"]=1;                    
        // 注册用于判断登陆的成功的session变量
        header("Location:index.php");
    }
    else
    {
     echo '<font color="red">用户名或密码错误</font>';
    }
    // session_destroy();
}
?>
<!DOCTYPE html>
<html>
<head>
 <title>邮件登录系统</title>
 <style>
     div span{width:100px;text-align:right;}
 </style>
</head>
<body>
    <p>
    欢迎来到邮件系统:session ID <?php echo session_id(); ?>
    </p>
    <form action="login.php" method="post">
   <span>用户名:<input type="text" name="username"><br></span><br>
   <span>密 码:<input type="password" name="password"><br></span><br>
   <input type="submit" name="sub" value="登陆"></input>
    </form>
</body>
</html>


 

$stmt = $pdo->prepare("SELECT id,username FROM user WHERE username=? and userpwd=?"); $stmt -> execute(array($_POST["username"],md5($_POST["password"]) ));

in these lines has an error:syntax unexpected $stmt, i use it with PDO ,I dont know where is the problem,that way of writting should be ok,isn it?

the hole project is here:https://github.com/he1986yuan/exercise.git in the document named email

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
宋春亮
  • 3
  • 3
  • 3
    While re-formatting your code, I've noticed strange new-line characters. Please ensure that you add new-lines after comments. It seems to me that those asian(?) characters somehow break encoding. To test out my theory, remove all comments and try to run it again. – Alex Tartan Mar 19 '16 at 11:52
  • thankyou ,I have tried,but still dont work。theyre just comments – 宋春亮 Mar 19 '16 at 12:14

1 Answers1

0

In this line:

  if(isset($_POST['sub']))
  {                                      //使用从表单中接收到的用户名和密码,作为在user表中的查询条件
// --------------------------====================

the spaces marked with  =  are not spaces (they are other utf8 chars): on my side, I have removed these characters and Syntax error disappears.

The  =  characters are unicode 3000, an Ideographic Space.

fusion3k
  • 11,568
  • 4
  • 25
  • 47