Simple Login System
==================================================
Here i used php as language and mysql as database
1st of all i introduce database access codes for mysql......
---------------------------------------
Named config.php
then i created displaying page named as home.php
----------body codes-------------
<!-- Starts form when click button, login.php(will shows later here) willexicutes -->
<form action="login.php" method="Post" name="form2" id="form2">
<!-- User select box------------------------------- -->
User: <select name="myusername" id="myusername" >
<option>Acadamic</option>
<option>Student</option>
<option selected="selected">Administration</option>
</select>
<!-- Password box ------------------------->
Password: <input name="mypassword" type="password" id="mypassword" />
<!-- Submit Button ---------------------->
<input name="submit1" type="submit" id="select" value=" Submit " />
</form>
<!-- Closed form -------------------->
--------------over body part-------------
All the actions will executes here Page Named as login.php
<div id="e">
<?php
session_start();
require("config.php"); //gathering database details
if($_POST) //if the button press
{
$connection = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Can not connect to the server");
$dbase = mysql_select_db("dbdatabase", $connection)
or die("Can not access data base");
$username = $_POST['myusername'];
$password1 = $_POST['mypassword'];
$password =md5($password1);
//there is a db table called "user"
$query = "SELECT * FROM user WHERE UserID ='$username' and Password ='$password1'";
$result = mysql_query($query);
//to counts the number of rows in database
$numrows = mysql_num_rows($result);
if($numrows > 0)
{
/*session_regenerate_id();*/
$member=mysql_fetch_assoc($result);
//session_register("USERNAME");
session_register("USERID");
session_register("LoginStatus");
//storing data to session variables
$_SESSION['USERID'] = $member['UserID'];
//storing data to session variables
$_SESSION['LoginStatus']= $member['loginStatus'];
switch($_SESSION['LoginStatus'])
{
case 1:
header('Location:../pages/Login Admin.php');//log to admin page
break;
case 2:
header('Location:../pages/Login lecturer.php');//log to lecturer page
break;
case 3:
header('Location:../pages/Login Student.php');//log to student page
break;
}
}
else
{
echo "Error password";
}
}
?>
</div>
-------------------------------------------------------------------------
Database file
Table structure for table `user`
CREATE TABLE IF NOT EXISTS `user` (
`loginStatus` int(11) NOT NULL,
`UserID` varchar(30) NOT NULL,
`Password` varchar(30) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Dumping data for table `user`
INSERT INTO `user` (`loginStatus`, `UserID`, `Password`) VALUES
(2, 'Acadamic', 'lec'),
(1, 'Administration', 'admin'),
(3, 'Student', 'stu');
=======================================================================
Please try on these...........................................
<b>Irantha Jayasekara
B.Sc(UG) in Computer Science & Technology(special)
SUSL </b>
No comments:
Post a Comment