Hello, I'm trying to get a user from database users with admin field of Y, to be directed to page a, and admin field of N to go to page b. I'm failing at this.
bunch of variables up here...
$sql = "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password' AND admin='$admin' LIMIT 1";
$run = mysql_query($sql);
$count = mysql_num_rows($run);
then admin Y page checks if session user and admin is filled
and admin N page checks if session user is filled. The code on those pages are right(i think), but It's probably my method of going about this is wrong.
02-03-2013, 02:26 AM
simplypixie
The first glaring issue I see is that you are using one = instead of two (you need two to compare values, ie. 'is equal to') and you have not put your Y and N in quote marks (as they are not integers), they should be
PHP Code:
if ($count > 0) && ($admin == 'Y')
if ($count > 0) && ($admin == 'N')
However I also don't know where your $admin variable is being set and assigned a value so that could also be causing a problem.
02-03-2013, 02:08 PM
jazzmasterkc
Thank you,
and I wish to set the variable durring the query so I can keep track of it. $admin first apears here: AND admin='$admin' (durring the query)
What would be the proper way of going about this?
02-03-2013, 02:19 PM
simplypixie
What you have in your query means that AND admin='The value assigned to the variable $admin', therefore a value has to have been assigned to the variable $admin before you can use it in your query.
However, looking at your query you are actually trying to work out the value of admin stored in the database for the user who is logging in and therefore your query should just be
PHP Code:
$sql = "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password' LIMIT 1";