When I test the following code it displays 1 on the next page not the username. Can someone please help me solve this problem? Thanks in advance.
This code is to login:
This is code on the next page:
This code is to login:
Code:
require "config.php";
$admin_username = $_POST['admin_username'];
$admin_password = $_POST['admin_password'];
if (isset($_POST['login'])) {
md5($admin_password);
$check = mysql_query ("SELECT COUNT(*) FROM tbl_admin WHERE admin_username='". mysql_real_escape_string($admin_username) . "' AND admin_password ='". mysql_real_escape_string($admin_password) . "'") or die ("Query did not work because: ".mysql_error());
$result = mysql_result ($check, 0, 0);
if ($result >= 1) {
setcookie ("admin_username", $result['admin_username']);
setcookie ("admin_password", $result['admin_password']);
header('Location: products.php');
exit;
} else {
echo "Sorry, don't know who you are.";
}
}
mysql_close();
This is code on the next page:
Code:
session_start();
if (isset($_COOKIE['admin_username']) && ($_COOKIE['admin_password'])) {
echo "You are logged in as: " . $_COOKIE['admin_username']."<br />";
echo "<a href=logout.php>Logout</a>";
} else {
echo "Welcome, <b>Guest</b>. Please login or <a href=registration_form.php>register</a>.<br />";
echo "<form name=loginform method=post action=login.php><input type=text name=admin_username id=admin_username><input type=password name=admin_password id=admin_password><input name=login type=submit id=login value=LOGIN></form>";
}