Jump to content

Password Validation


Schlo_50

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!
Link to comment
https://forums.phpfreaks.com/topic/22120-password-validation/
Share on other sites

Archived

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

×
×
  • 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.