-2

解析错误:第 70 行 C:\wamp\www\Discussion Forums\login.php 中的解析错误

这是我的代码。顺便说一句,我正在制作一个登录页面,其中包含功能配置(用于数据库连接)、页眉和页脚页面,并且我使用 WampServer 和 Dreamweaver。

<?php
session_start();
require("config.php");
require("functions.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
if($_POST['submit']) 
{
    $sql = "SELECT * FROM users WHERE username = '"
    . $_POST['username'] . "' AND password = '"
    . $_POST['password'] . "';";
    $result = mysql_query($sql);
    $numrows = mysql_num_rows($result);
    $result = mysql_query($sql);
    $numrows = mysql_num_rows($result);
    if($numrows == 1) 
        {
            $row = mysql_fetch_assoc($result);
            if($row['active'] == 1) 
                {
                    session_register("USERNAME");
                    session_register("USERID");
                    switch($_GET['ref']) 
                    {
                        case "newpost":
                        if(isset($_GET['id']) == FALSE) 
                            {
                                header("Location: " . $config_basedir .
                                "/newtopic.php");
                            }
                        else 
                            {
                                header("Location: " . $config_basedir .
                                "/newtopic.php?id=" . $_GET['id']);
                            }
                        break;
                        case "reply":
                        if(isset($_GET['id']) == FALSE) 
                            {
                                header("Location: " . $config_basedir .
                                "/newtopic.php");
                            }
                        else 
                            {
                                header("Location: " . $config_basedir .
                                "/newtopic.php?id=" . $_GET['id']);
                            }
                        break;
                        default:
                        header("Location: " . $config_basedir);
                        break;
                    }
                }
                else {
                require("header.php");
                echo "This account is not verified yet. You were emailed a link
                to verify the account. Please  click on the link in the email to
                                                        continue.";
                }
            echo "This account is not verified yet. You were emailed a link
          to verify the account. Please click on the link in the email to
          continue.";
        }
}
else {
header("Location: " . $config_basedir . "/login.php?error=1");
}
else {
require("header.php");
if($_GET['error']) {
echo "Incorrect login, please try again!";
}
}
?>
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>"
  method="post">
<table>
    <tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" name="submit" value="Login!"></td>
    </tr>
</table>
</form>
Don't have an account? Go and <a href="register.php">Register</a>!

<?php
 }
  require("footer.php");
?>
4

3 回答 3

8

这是你的问题:

else {
header("Location: " . $config_basedir . "/login.php?error=1");
}
else {

你有两个连续else的。你应该修改你的代码。

于 2012-10-23T15:18:07.993 回答
0

前行没有匹配else。也就是说,打开和关闭大括号不匹配。 保持代码缩进有助于避免此类错误。require("header.php");if

于 2012-10-23T15:19:23.850 回答
0

在第 67 行使用 else if($somecondition) 代替,因为在 if-elseif-else 中只能有一个 else 块。您的逻辑也存在错误,我正在输入可能对您有所帮助的新代码。

      <?php
session_start();
require("config.php");
require("functions.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
if($_POST['submit']) 
{
    $sql = "SELECT * FROM users WHERE username = '"
    . $_POST['username'] . "' AND password = '"
    . $_POST['password'] . "';";
    $result = mysql_query($sql);
    $numrows = mysql_num_rows($result);
    $result = mysql_query($sql);
    $numrows = mysql_num_rows($result);
    if($numrows == 1) 
        {
            $row = mysql_fetch_assoc($result);
            if($row['active'] == 1) 
                {
                    session_register("USERNAME");
                    session_register("USERID");
                    switch($_GET['ref']) 
                    {
                        case "newpost":
                        if(isset($_GET['id']) == FALSE) 
                            {
                                header("Location: " . $config_basedir .
                                "/newtopic.php");exit;
                            }
                        else 
                            {
                                header("Location: " . $config_basedir .
                                "/newtopic.php?id=" . $_GET['id']);exit;
                            }
                        break;
                        case "reply":
                        if(isset($_GET['id']) == FALSE) 
                            {
                                header("Location: " . $config_basedir .
                                "/newtopic.php");exit;
                            }
                        else 
                            {
                                header("Location: " . $config_basedir .
                                "/newtopic.php?id=" . $_GET['id']);exit;
                            }
                        break;
                        default:
                        header("Location: " . $config_basedir);
                        break;
                    }
                }
                else {
                    //require("header.php");
                        $msg = base64_encode("This account is not verified yet. You were emailed a link
                      to verify the account. Please click on the link in the email to
                      continue.");
                      header("Location: " . $config_basedir . "/login.php?msg=".$msg);exit;
                }
                    $msg = base64_encode("This account is not verified yet. You were emailed a link
                  to verify the account. Please click on the link in the email to
                  continue.");
                  header("Location: " . $config_basedir . "/login.php?msg=".$msg);exit;

        }else{
             $msg = base64_encode("You have incorrect username or password");
                  header("Location: " . $config_basedir . "/login.php?msg=".$msg);exit;
        }
}

require("header.php");
if($_GET['msg']) {
    echo base64_decod($msg);
}

?>
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>"
  method="post">
<table>
    <tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" name="submit" value="Login!"></td>
    </tr>
</table>
</form>
Don't have an account? Go and <a href="register.php">Register</a>!

<?php

  require("footer.php");
?>
于 2012-10-23T15:37:05.190 回答