cturner Posted October 29, 2006 Share Posted October 29, 2006 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.[code]require "config.php";$admin_username = $_POST['admin_username'];$admin_password = $_POST['admin_password'];if (isset($_POST['login'])) {md5($admin_password);$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'); exit;} else { echo "Sorry, don't know who you are.";}}mysql_close();[/code] Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 29, 2006 Share Posted October 29, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.