User Login with activation check using PHP and MySql
we will login a user based on the user is active or not, if the user is active, he is able to access otherwise he will be shown with an error message.
First, we are connecting to the database, and taking the input values from user, if the user name, password matches and the account is active we will allow him to the user’s area. Other wise we will display an error message.
I think you have worked on the previous code for registration, if so you have table, otherwise create table from the previous script and dump in the some values.
First, we are connecting to the database, and taking the input values from user, if the user name, password matches and the account is active we will allow him to the user’s area. Other wise we will display an error message.
I think you have worked on the previous code for registration, if so you have table, otherwise create table from the previous script and dump in the some values.
We are creating two pages.
- connect.php
- login.php
Connect.php
1 | <?php |
2 | $connection = mysql_connect( 'localhost' , 'root' , '' ); |
3 | if (! $connection ){ |
4 | die ( "Database Connection Failed" . mysql_error()); |
5 | } |
6 | $select_db = mysql_select_db( 'test' ); |
7 | if (! $select_db ){ |
8 | die ( "Database Selection Failed" . mysql_error()); |
9 | } |
login.php
view source
print?
1 | <?php |
2 | require_once 'connect.php' ; |
3 | if (isset( $_POST [ 'submit' ])){ |
4 | $username = $_POST [ 'username' ]; |
5 | $password = $_POST [ 'password' ]; |
6 |
7 | $sql = "SELECT * FROM `confirm` WHERE username='$username' and password='$password' and active=1" ; |
8 | $result = mysql_query( $sql ) or die (mysql_error()); |
9 | $count = mysql_num_rows( $result ); |
10 | if ( $count == 1){ |
11 | echo "You are logged in" ; |
12 | } else { |
13 | echo "Login Failed" ; |
14 | } |
15 | } |
16 | ?> |
17 | <html> |
18 | <head> |
19 | <title>Login</title> |
20 | </head> |
21 | <body> |
22 | <h1></h1> |
23 | <form action= "" method= "post" > |
24 | <label>User Name :</label> |
25 | <input type= "text" name= "username" /><br /> |
26 | <label>Password</label> |
27 | <input type= "password" name= "password" /><br /> |
28 | <input type= "submit" value= "Login" name= "submit" /> |
29 | </form> |
30 | <?php |
31 |
32 | ?> |
33 | </body> |
34 | </html> |
Subscribe to:
Posts
(
Atom
)
No comments :
Post a Comment