View Single Post
Old 04-08-2009, 03:52 PM   #1 (permalink)
murdocsvan
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default PHP not sure how to compare 2 fields.

Basically, i have a form, for creating new users on my database. It just has 3 fields; one for the username; one for the password and one to confirm the user put the right password in. Everything in the form works except comparing the two password fields to make sure they match. I've tested and tried loads of things but if they don't match they still add the user to the database anyway

This is the code for the end of the script:

PHP Code:
if(empty($username) ||  empty($password) || empty($confirm_password))
    {
    echo 
"Fields are empty";
    }
else
    {
    
//?????????????????????????????????????????????????//
    //???Problem comparing first and second password???//
    //?????????????????????????????????????????????????//
    
if($password != $confirm_password)
        {
        echo 
"New passwords did not match'";
        }
    else
        {
        
//Turn posted fields into sha1 values
        
$password sha1($password);
        
$confirm_password sha1($confirm_password);
        
        
//Determine what the ID number will be
        
$sql "SELECT * FROM $tbl_name";
        
$result mysql_query($sql,$con);
        
$num_rows mysql_num_rows($result);
        
$num_rows ++;
        
        
//Enter new user into database
        
$create "INSERT INTO $tbl_name (id, username, password) 
        VALUES('$num_rows', '$username', '$password')"
;
        
mysql_query($create,$con);
        
        
//Take user to Success! page
        
header("location:****.php");
        }
    } 

__________________

murdocsvan is offline