Jump to content

Recommended Posts

Parse error: syntax error, unexpected ')' in /home/commentb/public_html/demo/username_change.php on line 25

 

Other quick question, how do I make it if points are higher then 50 instead of just 50.

 

Code:

 

<?php require "global_navigation.php"; ?>
<?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.";
}

?></font></td>
										</tr>
									</tbody>
								</table></td>
							</tr>
						</tbody>
					</table>
					</td>
				</tr>
			</tbody>
		</table>
		</center>
		<table class="tborder" cellpadding="4" cellspacing="1" width="67%">
			<tbody>
				<tr>
					<td class="thead"><font face="Trebuchet MS"><strong>  
					Copyright</strong></font></td>
				</tr>
				<tr>
					<td class="trow1">
					<table border="0" cellpadding="4" width="100%">
						<tbody>
							<tr>
								<td class="trow1">
								<p align="center">
<span class="smalltext" style="display: inline; visibility: visible; font-family: Trebuchet MS; font-weight: 700">
<a title="Simple Machines Forum" target="_blank" class="new_win" href="http://commentbb.com">
<font size="2">Powered by CommentBB 1.0 BETA</font></a><font size="2"> |
</font><a href="http://commentbb.com"><font size="2">CBB is © 2009, CommentBB 
INC</font></a></span></td>
							</tr>
						</tbody>
					</table></td>
				</tr>
			</tbody>
		</table> </div>
<font face="Trebuchet MS">
<!-- end: footer -->
<!-- end: portal --></font></body></html>

Link to comment
https://forums.phpfreaks.com/topic/179804-solved-error-unexpected/
Share on other sites

There was more than one error in your code. Here it is, however, there is still an error due to your 'else' clauses. You need to define your logic better because as it stands it will not work. Here is the code with all possible corrections:

 

<?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.";
}

?>

 

Just so you know, require is a function, and >= is the operator for points greater than or equal to 50.

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.