Parse error: syntax error, unexpected T_ELSE in C:

Discussion in 'PHP' started by exzevia, Nov 2, 2010.

  1. #1
    Please help me with this error . here is the code : I am sorry about loading a lot but they are actually two error and the second one is below this one.

    <?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");
    $_SESSION['USERNAME'] = $row['username'];
    $_SESSION['USERID'] = $row['id'];
    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");
    ?>


    second one :parse error: syntax error, unexpected T_IS_EQUAL in C:
    here is the code:

    <?php
    session_start();
    require("config.php");
    require("functions.php");
    $db = mysql_connect($dbhost, $dbuser, $dbpassword);
    mysql_select_db($dbdatabase, $db);
    $forchecksql = "SELECT * FROM forums;";
    $forcheckresult = mysql_query($forchecksql);
    $forchecknumrows = mysql_num_rows($forcheckresult);
    if($forchecknumrows == 0) {
    header("Location: " . $config_basedir);
    }
    if(isset($_GET['id']) == TRUE) {
    if(is_numeric($_GET['id']) == FALSE) {
    $error = 1;
    }
    if($error == 1) {
    header("Location: " . $config_basedir);
    }
    else {
    $validforum = $_GET['id'];
    }
    }
    else {
    $validforum = 0;
    }
    if(isset($_SESSION['USERNAME']) == FALSE) {
    header("Location: " . $config_basedir . "/login.php?ref=newpost&id="
    . $validforum);
    }
    if($_POST['submit']) {
    if($validforum == 0) {
    $topicsql = "INSERT INTO topics(date, user_id, forum_id, subject)
    VALUES(NOW()
    , " . $_SESSION['USERID']
    . ", " . $_POST['forum']
    . ", '" . $_POST['subject']
    . "');";
    }
    else {
    $topicsql = "INSERT INTO
    topics(date, user_id, forum_id, subject) VALUES(NOW()
    , " . $_SESSION['USERID']
    . ", " . $validforum
    . ", '" . $_POST['subject']
    . "');";
    }
    mysql_query($topicsql);
    $topicid = mysql_insert_id();
    $messagesql = "INSERT INTO messages(date,
    user_id, topic_id, subject, body) VALUES(NOW()
    , " . $_SESSION['USERID']
    . ", " . mysql_insert_id()
    . ", '" . $_POST['subject']
    . "', '" . $_POST['body']
    . "');";
    mysql_query($messagesql);
    header("Location: " . $config_basedir . "/viewmessages.php?id=" .
    $topicid);
    }
    else {
    require("header.php");
    if($validforum != 0) {
    $namesql = "SELECT name FROM forums ORDER BY name;";
    $nameresult = mysql_query($namesql);
    $namerow = mysql_fetch_assoc($nameresult);
    echo "<h2>Post new message to the " . $namerow['name'] . "
    forum</h2>";
    }
    else {
    echo "<h2>Post a new message</h2>";
    }
    ?>
    <form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>"
    method="post">
    <table>
    <?php
    if($validforum) == 0) {
    $forumssql = "SELECT * FROM forums ORDER BY name;";
    $forumsresult = mysql_query($forumssql);
    ?>
    <tr>
    <td>Forum</td>
    <td>
    <select name="forum">
    <?php
    while($forumsrow = mysql_fetch_assoc($forumsresult)) {
    echo "<option value='" . $forumsrow['id'] . "'>" .
    $forumsrow['name'] . "</option>";
    }
    ?>
    </select>
    </td>
    </tr>
    <?php
    }
    ?>
    <tr>
    <td>Subject</td>
    <td><input type="text" name="subject"></td>
    </tr>
    <tr>
    <td>Body</td>
    <td><textarea name="body" rows="10" cols="50"></textarea></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="submit" value="Post!"></td>
    </tr>
    </table>
    </form>
    <?php
    }
    require("footer.php");
    ?>
     
    exzevia, Nov 2, 2010 IP
  2. kai555

    kai555 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi

    the first error:

    look at

    }
    else {
    header("Location: " . $config_basedir . "/login.php?error=1");
    }
    else {
    require("header.php");
    if($_GET['error']) {

    You end an else and then have a second else right after it. You can't do this:
    if (){
    }
    else{
    }
    else{
    }

    doesn't make sense.

    The second error:

    Look at this line:
    if($validforum) == 0) {

    you have the extra )
    maybe it should be:
    if($validforum == 0) {

    :) hope it makes sense.
     
    kai555, Nov 3, 2010 IP