-1

我正在编写一个根据 youtube 教程验证登录的表单:http ://www.youtube.com/watch?v=mn0ucCuNOTI 。

问题是我不能让这个特定的页面工作:

    <?php include_once("db.php") 
     session_start();
     ?>

    <?php
$user = $_POST['name'];
$pass = $_POST['pwd'];

 $sql="SELECT count(*) from phplogin WHERE(username='$user' and password='$pass')";

$query = mysql_query($sql);

$result = mysql_fetch_array($query);

if($result[0] > 0) {
    $_SESSION['userName']=$user;
    echo "Succesful login!";

    echo "<br /> Welcome " .$_SESSION['userName']. "!";
    echo "<br /><a href='signupform.php' > SignUp </a>";
    echo "<br /><a href='signinform.php' > SignIn </a>";
    echo "<br /><a href='logout.php' > LogOut </a>";
}
else{
echo "Login failed!";
echo "<br /><a href='signupform.php' > SignUp </a>";
echo "<br /><a href='signinform.php' > SignIn </a>";

}
?>

问题是当我删除 start_session() 时,该站点工作(当然我还没有开始真正使用该会话)。我不知道问题是否出在我的代码中。

现在我收到以下错误消息: Parse error: syntax error, unexpected 'session_start' (T_STRING) in C:\webserver\apache\htdocs\sign_in_up\signin.php on line 2

4

3 回答 3

3

您只是在include_once声明后缺少一个分号:

<?php
   include_once("db.php"); // Added the missing semi-colon
   session_start();
?>
于 2013-08-21T23:46:47.480 回答
2

You have a missing semi-colon.

<?php include_once("db.php"); 
 session_start();
 ?>

PHP cannot process the next function correctly due to this missing syntax.. Hence the error showing on the next line.

于 2013-08-21T23:47:33.073 回答
2

尝试这个:

<?php include_once("db.php") ;//semi-colon was missing
     session_start();
     ?>
于 2013-08-21T23:47:05.350 回答