How to fetch a MySQL table field value in a numeric PHP variable to use it in an IF statement?

I have a MySQL table 'log' with columns 'idUser', 'password', 'priority'. Depending on the 'priority' value (1 or 2) I try to access different PHP pages from the login.php page. I don't know how to store the value of 'priority' in a PHP variable, for using it in an IF statement:

$_SESSION['username'] = $user;
$_SESSION['password'] = $pass;
$sql = "SELECT priority FROM log WHERE idUser = '$user' AND password = '$pass'";
$p = mysql_query($sql);
$r = mysql_fetch_row($p);
 <!--?? -->  
if ($r==1)
{header('Location: page1.php');}
else
{header('Location: page2.php');}

Answers


First off, the mysql_* functions have been deprecated and replaced with the mysqli_* functions.

for your question however, in your if statement $r is an array so whatever column you want needs to be addressed as such $r['priority'] or $r[2] or whatever the index of that column is

here is your code corrected:

$_SESSION['username'] = $user;
$_SESSION['password'] = $pass;
$sql = "SELECT priority FROM log WHERE idUser = '$user' AND password = '$pass'";
$p = mysql_query($sql);
$r = mysql_fetch_row($p);
 <!--?? -->  
if ($r[0]==1)
{header('Location: page1.php');}
else
{header('Location: page2.php');}

Need Your Help

JSONString won't convert to JSONArray

android json bluetooth android-bluetooth android-json

I am attempting to send a string json of teams through Bluetooth to another android device. For some reason the Serializer will load a small list of teams but a large list of teams causes this err...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.