I have a logic error I cannot for the life of me figure out. The problem is this very very basic login page I have written is always outputting the default answer as opposed the the choice from the table.
I am trying to return to the php the value in E_Type in this case the value should return A, however it is not.
What am I doing wrong?
Code:
<?php
$server = -Removed;
$login = -Removed;
$pass = -Removed;
$login = $_POST['login'];
$password = $_POST['password'];
$table = 'USERPASS';
$table2 = 'EMPLOYEES';
$res = 'q';
$dblink = @mssql_connect(-Removed) or die("Error 1");
mssql_select_db('group5', $dblink) or die( "unable to select the database");
$sqlquery = "SELECT E_TYPE FROM USERPASS U, EMPLOYEES E WHERE U.EMPLOYEE_ID = E.EMPLOYEE_ID AND PASSWORD = '$password' AND USERNAME = '$login'";
$res = mssql_query($sqlquery, $dblink) or die("Error5");
$count = mssql_num_rows($res);
if($count==1)
{
if ($res == "A" )
{
echo "Success 1";
}
else if ($res == "B" )
{
echo "Success 2";
}
else
{
echo "Error...";
}
}
?>
You need to fetch the result first. In
$resyou basically only have a result handle that can iterate over the results.Use
mssql_fetch_assocto fetch the results and access them (this would loop over all resulting rows):In your case (if you only expect a single row) use this: