-2

Parse error: parse error in C:\wamp\www\Discussion Forums\login.php on line 70

Here is my code. By the way, I'm making a login page which has functions config (for database connectivity), header and footer page , and I use WampServer and 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");
?>
Zbigniew
  • 27,184
  • 6
  • 59
  • 66
  • 8
    Any chance of flagging up which is line 70? – andrewsi Oct 23 '12 at 15:16
  • 2
    if you just started, I need to warn you that your SQL code is very *very* bad. Wherever you're getting your tutorials from, stop reading them and find something better. You need to read this: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-function-in-php/12860030#comment17693445_12860030 and this: http://www.phptherightway.com/ for starters. – SDC Oct 23 '12 at 15:21
  • 1
    Please, don't use `mysql_*` functions to write new code. They are no longer maintained and the community has begun [deprecation process](http://goo.gl/KJveJ). See the [*red box*](http://goo.gl/GPmFd)? Instead you should learn about [prepared statements](http://goo.gl/vn8zQ) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide which, [this article](http://goo.gl/3gqF9) will help you. If you pick PDO, [here is good tutorial](http://goo.gl/vFWnC). – tereško Oct 23 '12 at 15:21

3 Answers3

8

Here is your problem:

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

You have two consecutive else's. You should revise your code.

Omid Kamangar
  • 5,768
  • 9
  • 40
  • 69
0

The else before require("header.php"); line does not have matching if. That is, opening and closing curly brackets do not match.
Keeping code indented helps to avoid such errors.

bhovhannes
  • 5,511
  • 2
  • 27
  • 37
0

On line number 67 use else if($somecondition) instead because in if-elseif-else can have only one else block. Also there is errors in your logic I am putting the new code it may help you.

      <?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");
?>
Tariq Aziz
  • 788
  • 3
  • 13
  • 29