Select value from database and store into a temporary variable
- by user1616230
I want to select a stored value from database and then put it into a temporary variable.
For example, I have a column called category, one value under it is m, so I want to select this m value from the database, let's say from a table of a database called user_info.
Then I want to put it into a variable, let's name it $res.
After that, I want to do some condition stuff, such as if $res=="m",
Can anyone help me write a simple structure here?
Here is the code:
<?php
$sql = "Select category FROM user_info WHERE user_name = '"
.$_SESSION['username']."' and password = '".$_SESSION['password']."'";
$res = mysql_query($sql);
if($res == "a"){
include('MPIncomeStrategy.php');
}
if($res == "b"){
include('MPIncomeStrategy.php');
}
But it seems that the code is not able to detect $res =="category value in database". Did I just use the wrong way to store the category value?