Select value from database and store into a temporary variable

Posted by user1616230 on Stack Overflow See other posts from Stack Overflow or by user1616230
Published on 2012-08-30T18:18:51Z Indexed on 2012/09/01 3:38 UTC
Read the original article Hit count: 83

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql