I am logging in a user with PHP and have everything working but getting the session to set properly with the value from the id row. My database looks similar to this.
---------------------------------------------------------|
| id | email | password | name |
| 7 | someone@domain.com | secret | Joe |
---------------------------------------------------------|
Here is the logic on my login page. The form is working and setting $_SESSION['id'] but it doesn't have a value.
CODE
session_start();
if(array_key_exists('login', $_POST)) {
/* Make inputs safe to use. */
$email = htmlspecialchars($_POST['email']);
$password = htmlspecialchars($_POST['password']);
$errors = array();
$dbpassword = mysql_query('SELECT password FROM users WHERE email=(\''.$email.'\')');
if($dbpassword != crypt($password, $dbpassword)) {
$errors[] = 'Please enter a valid email and password.';
} else {
$userid = mysql_query('SELECT `id` FROM `users` WHERE `email` = \''.$email.'\'');
$_SESSION['id'] = $userid;
header('Location: home.php?');
}
}