The given PHP example helps you to make a simple password authentication form.
<?php
if (! empty ( $loginme )) { |
$connection = mysql_pconnect( $dbhost = 'localhost' , $dbuser = 'root' , $dbpass = 'root' ); |
mysql_select_db( $database = 'test' , $connection ); |
$query = "SELECT id FROM customer WHERE email='" .mysql_real_escape_string( $admin ). "' AND password='" .mysql_real_escape_string( $password ). "'" ; |
$result = mysql_query( $query , $connection ); |
$num = mysql_num_rows( $result ); |
if ( $num > 0){ |
header( "Location: home.php" ); // do what you want |
exit ; |
} |
else { |
echo "username and password are either incorrect or not in the database" ; |
} |
} |
?> |
<form method= "post" action= "" > |
Username: <input type= "text" name= "admin" ><br> |
Password: <input type= "password" name= "password" ><br> |
<input type= "submit" name= "loginme" value= "Login Me" > |
</form>
No comments:
Post a Comment