//declare variables
$thing = $_SESSION['username'];         // get username from session
$name = mysql_real_escape_string($_REQUEST['name']);
$pwrd = mysql_real_escape_string($_RQUEST['pass']);    
//$mpwrd= md5($pwrd);
$error = 0;
$select = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($select);
$check =  mysql_query("SELECT * FROM users WHERE username='$name'");
$check2= mysql_num_rows($check);




            //if submitted
    if (isset($_POST['submit'])){
 
       
            if(!$name){
                 $error ++;
					echo "Please fill out all the fields!<br>";
                 }
			/*if($numrows == 0){
               $error ++;
					echo "Sorry the inputed username does not exist<br>"; 
			}*/
			if($check2 !=0){
               $error ++;
					echo "Sorry the inputed username is already taken!<br>"; 
			}
            if ($numrows > 0){

				//get user info from db
					while ($row = mysql_fetch_assoc($select)){
							$dbusername = $row['username'];
							$dbpassword = $row['password'];
							$id = $row['id'];}
							}
			if ($pwrd != $dbpassword){
				$error ++;
					echo "You're password is incorrect<br>";
			}
			
			if(!$error){
                     mysql_query("UPDATE users SET username=$name WHERE username='$thing");
					 echo "username changed";
					 
					 }

                 else
                  echo 'Your username was not changed due to an error.';






    }
   // error count on the form.
   print "There are currently " .  $error  ." error(s)";

?>

for some reason it just won't update can anyone point out the error it's probably staring me right in the face but i just don't see it..

for one, you want quotes around $username

#
mysql_query("UPDATE users SET username='$name' WHERE username='$thing");

#2) Protip:here's a debugging tip when SQL won't work. it will always surface itself this way.


step 1)echo the sql in your code
step 2)paste the code into a sql client like pgadmin or mysql or phpmyadmin, etc
step 3) look for the error that the DB returns
step 4) fix it in your code.


learn those steps. it's vital to finding bugs on your own for any php developer who uses DBs

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.