Jump to content

Archived

This topic is now archived and is closed to further replies.

Schlo_50

Password Validation

Recommended Posts

To add some validation to my register form, i thought it would be a good idea to make the end user re-enter their chosen password in order for it to be correct. But im not sure what the line of code would be to only allow the form to be submitted if the passwords match.

<?php
$self=$_SERVER['PHP_SELF'];
$firstname=$_POST['first_name'];
$surname=$_POST['sur_name'];
$username=$_POST['user_name'];
$password=$_POST['password'];
$rpassword=$_POST['password'];
?>
<center><form action="blah blah" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="sur_name"><br>
Username: <input type="text" name="user_name"><br>
Password: <input type="password" name="password"><br>
Re-Password: <input type="password" name="password"><br>
<input type="Submit">
</form></center>

<?php

{
$conn = mysql_connect( "localhost","username","password" )
or die( "Err:Conn" );
$rs = mysql_select_db( "dombar0_work", $conn )
or die( "Err:Db" );
$sql = "INSERT INTO users ( first_name,sur_name,user_name,password ) VALUES
( \"$firstname\",\"$surname\",\"$username\",
                             password(\"$password\") )";

$rs = mysql_query( $sql, $conn );
if ($rs){ echo( "Details Added Successully $username" ); }
}
?>

I assume i need an if statement before the '$conn' line? Could someone give me the line that will check to see if the passwords match before connecting to the database please? Thanks guys!

Share this post


Link to post
Share on other sites
[code=php:0]
if ($password == $rpassword) {
  // connect and do insert
}
[/code]

Share this post


Link to post
Share on other sites
$password=$_POST['password'];
$rpassword=$_POST['password'];

You are also using the same post on both variables, it will always match..........

rename the second password-field to rpassword or whatever and post declare it

Share this post


Link to post
Share on other sites
I noticed that after i posted it, lol I still need the line of code to validate the password and the re-entering of the password though.

Share this post


Link to post
Share on other sites

×

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.