Jump to content


Not staying logged in???

  • Please log in to reply
1 reply to this topic

#1 cturner

  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 29 October 2006 - 03:42 AM

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.";

#2 Psycho

  • Moderators
  • Move along, nothing to see here
  • 11,892 posts
  • LocationCanada

Posted 29 October 2006 - 05:28 AM

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.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users