Jump to content


This topic is now archived and is closed to further replies.


Not staying logged in???

Recommended Posts

When I test the following code and then go to another page it says that I am not logged in. Can someone please tell me how I can fix this problem? Thanks in advance.

require "config.php";
$admin_username = $_POST['admin_username'];
$admin_password = $_POST['admin_password'];
if (isset($_POST['login'])) {
$check = "SELECT COUNT(*) FROM tbl_admin WHERE admin_username='". mysql_real_escape_string($admin_username) . "' AND admin_password ='". mysql_real_escape_string($admin_password) . "'";

$query = mysql_query ( $check ) or die ("Query did not work because: ".mysql_error());

if (mysql_num_rows ($query)) {
$row = mysql_fetch_assoc($query);
setcookie ("admin_username", $row['admin_username']);
setcookie ("admin_password", $row['admin_password']);
header('Location: products.php');
} else {
    echo "Sorry, don't know who you are.";

Share this post

Link to post
Share on other sites
When you say "go to another page" I am assuming that you are going to anothr page in your site and are running the validatin check above on that page as well. If that is the case then that explains the problem. When you submit a form, the values of the form (i.e. the $_POST values) are only available on the next page.

I suggest you save the login information to session variables. Thenthe validation script should first look to see if those exist and validate against that. If they do not exist, then see if the $_POST values exist and attempt to validate against those.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.