Page 1 of 1

register username problem

Posted: Wed Feb 18, 2015 12:26 am
by raven9704
hello

i am facing problem when in register page.when i register username then it lets me register same name more than 1 time.what is problem in this code.

help please.

Code: Select all

if(isset($_REQUEST['submit'])) 
     
    { 
        $u=$_REQUEST['user']; 
         
    $p=base64_encode($_REQUEST['pass']); 
     
    $g=$_REQUEST['gen']; 
     
    $e=$_REQUEST['email']; 
     
    $d=$_REQUEST['day']; 
     
    $m=$_REQUEST['month']; 
     
    $y=$_REQUEST['year']; 
     
     
     
    $sql = "SELECT * FROM register WHERE username = $u and password = $p"; 
        $result = mysql_query($sql); 
        //return $result; 
         
         
        if(!$result){ 
     echo mysql_error(); 
} 
         
         
        $num_rows = mysql_num_rows($result); 
         
        if ($num_rows > 0) { 
             
            echo "Username already taken"; 
        } 
         
         
         
         
        else{ 
     
    insert($u, $p, $g, $e, $d, $m, $y); 
        echo "Record inserted"; 

                 
                 
                 
     
    } 
     
    } 
     

Re: register username problem

Posted: Wed Feb 18, 2015 6:09 am
by Celauran
You aren't checking if a username exists, you are checking if combination of username and password exists. That's the problem you're asking about. Other problems are mysql_ functions, SQL injection, and improperly storing passwords.

Re: register username problem

Posted: Sun Feb 22, 2015 10:00 pm
by raven9704
will u plz post exact code and edit mine code.