Nirutechnolabs

Learning & Integrating web technology and code help directory

User Login with activation check using PHP and MySql

No comments
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.

We are creating two pages.
  1. connect.php
  2. login.php

Connect.php

1<?php
2$connection = mysql_connect('localhost''root''');
3if (!$connection){
4    die("Database Connection Failed" . mysql_error());
5}
6$select_db = mysql_select_db('test');
7if (!$select_db){
8    die("Database Selection Failed" . mysql_error());
9}

login.php

view source
print?
1<?php
2require_once 'connect.php';
3if (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($sqlor die(mysql_error());
9$count = mysql_num_rows($result);
10if ($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>

No comments :

Post a Comment