Try this (not tested but should work):
Code:
<?php
session_start();
####### Configuration ########
$DBserver = "localhost"; //server for Database
$DBuser = "USERNAME"; //user for MySQL Database
$DBpass = "PASSWORD"; //password for above mentioned username
$DB = "DATABASE"; //database the tables are located in
$usersTable = "user"; //Table the user information is in
$redirect = "admintasks.php"; //page to redirect to on successful login
####### End Config ########
$conn = mysql_connect($DBserver, $DBuser, $DBpass);
mysql_select_db($DB, $conn);
if (@$_POST['act'] == "do_login") {
$username = $_POST['username'];
$password = $_POST['password'];
$userInfo = mysql_query("SELECT * FROM `$usersTable` WHERE `username`= '$username'");
if (mysql_num_rows($userInfo) < 1) {
echo 'There are no users with that username in the database. Please go back and enter a valid username/password combination.';
}
else {
$q = mysql_fetch_array($userInfo);
if ($q['password'] != $password) {
echo 'The password is invalid. Please go back and enter a valid username/password combination.';
}
else {
$_SESSION['id'] = $q['id'];
$_SESSION['username'] = $q['username'];
$_SESSION['password'] = $q['password'];
header('Location: '.$redirect);
}
}
}
else {
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="hidden" name="act" value="do_login">
Username: <input type="text" name="username" value=""> <br>
Password: <input type="password" name="password" value=""> <br>
<input type="submit" value="Login">
</form>
</body>
</html>
<?php
}
?>
Edit as you see fit.
Hope this helps.
Bookmarks