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
https://forums.phpfreaks.com/topic/179842-t_else-error/
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
https://forums.phpfreaks.com/topic/179842-t_else-error/#findComment-948768
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
https://forums.phpfreaks.com/topic/179842-t_else-error/#findComment-948769
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.