Jump to content

T_ELSE Error


3raser

Recommended Posts

Parse error: syntax error, unexpected T_ELSE in /home/commentb/public_html/demo/username_change.php on line 48

 

<?php require("global_navigation.php");

$name = $_SESSION['username'];
$newuser = $_POST['newuser'];

if ($_SESSION['username']) {

        if (strlen($newuser)<=$usermax) {
                echo "Username must be at least $usermax characters long!";
} else {

        //display data
        $get = mysql_query("SELECT * FROM users WHERE username='$name'");
        while ($row = mysql_fetch_assoc($get)) {
                 // get data
                 $points = $row['points'];
        }

        if ($points >=50) {

                //protection
                $before = array('(', ')', '^', '<', '>', '`', '*', '<script>', '</script>', ';DROP TABLE users;', 'users', 'DROP', 'TABLE');
                $after   = array('', '', '', '', '', '', '', '', '', '', '', '', '');
                $output  = str_replace($before, $after, $newuser);

                //connect
                $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!");
                mysql_select_db("$db") or die("Database fail!");

                //checking
                $query = mysql_query("SELECT * FROM users WHERE username='$output'");

                $numrows = mysql_num_rows($query);

                if ($numrows!=0) {
                        echo "This username is currently being used!";
                } else {
                        //write
                        mysql_query("UPDATE users SET username='$output' WHERE username='$name'") or die(mysql_error());

                        echo "<center><div class='box'><span style='color:green'>Thank you $name, you have successfully edited your username to: <b>$output</b> <a href='index.php'>Return home</a></span></div></center>";

                        $_SESSION['username']=$output;
                }
        } else {
        echo "Mo";
        }
} else {
        echo "You must be logged in to change your username.";
}

?>

Link to comment
Share on other sites

at the very bottom, .. on the line your error is on.. remove the "}" you have two of them. I'm not sure if its needed, or if its suppose to be there. If it doesn't work then.. put it back in, or if it does work, but doesn't.. work fully eg: missing }, then put it at the end. See what good that does.

 

Or if that dont work, on the else before.. remove one of the "}" you might be using 1 too many. It's usually the case, however.. I don't know that problem.. I have a similar issue on my thread :P

Link to comment
Share on other sites

Attempt this:

 

<?php require("global_navigation.php");

$name = $_SESSION['username'];
$newuser = $_POST['newuser'];

if ($_SESSION['username']) {

        if (strlen($newuser)<=$usermax) {
                echo "Username must be at least $usermax characters long!";
} else {

        //display data
        $get = mysql_query("SELECT * FROM users WHERE username='$name'");
        while ($row = mysql_fetch_assoc($get)) {
                 // get data
                 $points = $row['points'];
        }
    }

        if ($points >=50) {

                //protection
                $before = array('(', ')', '^', '<', '>', '`', '*', '<script>', '</script>', ';DROP TABLE users;', 'users', 'DROP', 'TABLE');
                $after   = array('', '', '', '', '', '', '', '', '', '', '', '', '');
                $output  = str_replace($before, $after, $newuser);

                //connect
                $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!");
                mysql_select_db("$db") or die("Database fail!");

                //checking
                $query = mysql_query("SELECT * FROM users WHERE username='$output'");

                $numrows = mysql_num_rows($query);

                if ($numrows!=0) {
                        echo "This username is currently being used!";
                } else {
                        //write
                        mysql_query("UPDATE users SET username='$output' WHERE username='$name'") or die(mysql_error());

                        echo "<center><div class='box'><span style='color:green'>Thank you $name, you have successfully edited your username to: <b>$output</b> <a href='index.php'>Return home</a></span></div></center>";

                        $_SESSION['username']=$output;
                }
        } else {
        echo "Mo";
        }
} else {
        echo "You must be logged in to change your username.";
}

?>

 

Appears the first ELSE statement wasn't closed...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.