
March 3rd, 2004, 02:34 AM
|
|
|
|
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313
Time spent in forums: < 1 sec
Reputation Power: 4
|
|
|
RE: Sessions tutorial?
Check these two scripts in your pages.. did you create the table in database and make sure about the MySQL connection.
(login.php)
php Code:
Original
- php Code |
|
|
|
<?php // login.php include ("functions.php"); if($_POST['submit']) { $username=$_POST['username']; $password=$_POST['password']; $error = login_check($username,$password); if($error==true) { $_SESSION['id'] = login($username,$password); header("Location: index.php"); } else } ?> <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> Username : <input type="text" name="username"><br> Password : <input type="password" name="password"><br> <input type="submit" name="submit" value="Login"> </form>
(functions.php)
php Code:
Original
- php Code |
|
|
|
<?php $hostName=""; $userName=""; $passWord=""; $dataBase=""; $conn = mysql_connect($hostName, $userName, $passWord) or die("Failed to connect to database!"); function secure () { if(!($_SESSION["id"]) || ($_SESSION["id"] == "")) header("Location: login.php"); } function login_check($username,$password) { if (trim($username) == "") $error .= "<li>Your username is empty.</li>"; if (trim($password) == "") $error .= "<li>Your password is empty.</li>"; $sql = "SELECT Username,Password FROM userLogin WHERE Username='$username' AND Password='$password'"; if($num) return TRUE else $error .="<li>Invalid username/password.</li>"; return $error; } function login($username,$password) { $sql = "SELECT ID FROM userLogin WHERE Username='$username' AND Password='$password'"; $id = $row['ID']; return $id; } ?>
|