Page 1 of 1

Issue With My Logic???

Posted: Sun Jul 15, 2007 3:27 pm
by dgny06
Hi All,

I am asking a new question on code that I was questioning yesterday, as my original issue was a syntax one. I am using the code below on a page to write one sentence if the user filling out the form on the previous page has an access level of 1 in my database. Even though I enter the username and password for a record in my db that has AccessLevel of 1, I get my "else" sentence. I thought it my be a problem with the values I am entering in my form but I tried hard coding the username and password into my query and it still did not work. Can anyone tell me if the logic I am using just will not work or if you could think of another issue? In case it matters, the AccessLevel column in my database is a VARCHAR. I tried switching to an INT but that still did not work.

Thanks again in advance for your help.


Code: Select all

<?PHP include("connection/connect.php"); ?>

<?PHP 

$UserName = $_POST["UserName"];
$Password = $_POST["Password"];

?>

Your entered a username of <b>"<?PHP echo $UserName; ?>"</b> and password of <b>"<?PHP echo $Password; ?>"</b>.

<p>&nbsp;</p>
<p>&nbsp;</p>


<?PHP

$FindUser = "select AccessLevel from tbUser where UserName = '$UserName' and Password = '$Password'";
$FoundUser = mysql_query($FindUser);

if ($FoundUser == "1")
	echo "This is what you see if you are Access Level 1";
else
	echo "You do not have access to this page.";
?>

Posted: Sun Jul 15, 2007 3:49 pm
by Zoxive
Your not fetching the data, you are only validating if the query returned true or false.

Code: Select all


<?PHP

$FindUser = "select AccessLevel from tbUser where UserName = '$UserName' and Password = '$Password'";
$result= mysql_query($FindUser);

if($result){ // This what you were doing
  echo 'Query has a result <br/>';
}else{
  echo 'Query failed <br/>';
}

$data = mysql_fetch_assoc($result); // You were missing this step

if ($data['AccessLevel'] == "1")
        echo "This is what you see if you are Access Level 1";
else
        echo "You do not have access to this page.";
?>
There are many ways to get your data back from mysql, i personally use mysql_fetch_array() the most.

Posted: Sun Jul 15, 2007 4:01 pm
by dgny06
Thank you so much for your help.