3raser Posted November 1, 2009 Share Posted November 1, 2009 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."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/179842-t_else-error/ Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 You never closed the bracket on this line: if ($_SESSION['username']) { And I'm guessing you're also mixing up some brackets. Quote Link to comment https://forums.phpfreaks.com/topic/179842-t_else-error/#findComment-948754 Share on other sites More sharing options...
3raser Posted November 1, 2009 Author Share Posted November 1, 2009 You never closed the bracket on this line: if ($_SESSION['username']) { And I'm guessing you're also mixing up some brackets. Yes I did, at the very bottom of the code. Quote Link to comment https://forums.phpfreaks.com/topic/179842-t_else-error/#findComment-948764 Share on other sites More sharing options...
Irresistable Posted November 1, 2009 Share Posted November 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/179842-t_else-error/#findComment-948768 Share on other sites More sharing options...
MrXander Posted November 1, 2009 Share Posted November 1, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/179842-t_else-error/#findComment-948769 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.