hi! I’m new to PHP. I got the script somewhere but when I tried to log in, it kept showing — Incorrect Username or Password —
what’s wrong with the script? I appreciate
michael
index.php
[code]
<?
// Use session variable on this page. This function must put on the top of page.
session_start();
////// Logout Section. Delete all session variable.
session_destroy();
$message=””;
////// Login Section.
$Login=$_POST[‘Login’];
if($Login){ // If clicked on Login button.
$username=$_POST[‘user_name’];
$md5_password=md5($_POST[‘user_pass’]); // Encrypt password with md5() function.
// Connect database.
$host=”localhost”; // Host name.
$db_user=””; // MySQL username.
$db_password=””; // MySQL password.
$database=””; // Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);
// Check matching of username and password.
$result=mysql_query(“select * from tablename where user_name=’$user_name’ and user_pass=’$md5_password'”) or die(mysql_error());
if(mysql_num_rows($result)!=’0′) { // If match.
session_register(“user_name”); // Craete session username.
header(“location:main.php”); // Re-direct to main.php
exit;
}else{ // If not match.
$message=”— Incorrect Username or Password —“;
}
} // End Login authorize check.
mysql_close($connect);
?>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<? echo $message; ?>
<form id=”form1″ name=”form1″ method=”post” action=”<? echo $PHP_SELF; ?>”>
<table>
<tr>
<td>User : </td>
<td><input name=”user_name” type=”text” id=”user_name” /></td>
</tr>
<tr>
<td>Password : </td>
<td><input name=”user_pass” type=”password” id=”user_pass” /></td>
</tr>
</table>
<input name=”Login” type=”submit” id=”Login” value=”Login” />
</form>
page.php
[code]
<?
// You may copy this PHP section to the top of file which needs to access after login.
session_start(); // Use session variable on this page. This function must put on the top of page.
if(!session_is_registered(“user_name”)){ // if session variable “username” does not exist.
header(“location:index.php”); // Re-direct to index.php
}
?>
<p>Hello <? echo $_SESSION[‘user_name’]; ?>! You are now Logged in.</p>
<p><a href=”index.php”>Logout</a></p>