yet again another problom with SESSIONS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

yet again another problom with SESSIONS

Post by dull1554 »

ok in my database i have a field called "type", this field contains either "user" or "admin", when i query the database all that is returned is the letter "e".

heres my code

login.php

Code: Select all

<?php
include "inc.php";
$username = stripslashes($_POST['user']);
$password = stripslashes($_POST['password']);
$query = mysql_query("SELECT password FROM users WHERE username='$username'");
$db = mysql_fetch_array($query);
$db_pass = $db['password'];
$userage = $db['age'];
$usertype = $db['type'];
if (md5($password) == $db_pass)
{
$_SESSION['user'] = $username;
$_SESSION['age'] = $userage;
$_SESSION['type'] = $usertype;

echo $_SESSION['type'];
}
else
{
echo "not found in database! please register!";
}
?>
//all that is contained in inc.php is the db connection.
does anyone know why it returns "e" nomatter what, and maybe a possiable soultion, i like sessions but i've been having lots of problems,

and by the way i don't get any errors and even when im not loged in, if i echo the session "type" it still returns "e" (this is after the session is destroyed)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You never select age and type from the db...
SELECT password FROM <----

The 'e' is coming from the word 'error' ;)
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

ahh i hate being stupid sometimes

thanks
Post Reply