Khamees Smith
Khamees Smith

Reputation: 31

PHP fetching Data from MYSQL

I am trying to fetch the flag field from mysql of the $_SESSION['sess_user'] But I dont know it never works with me... **

$c_user=$_SESSION['sess_user'];

    $queryflag = "SELECT `flag` FROM `members` WHERE `user`='" . $c_user . "'";
    $resultflag = mysql_query($queryflag);
    echo $resultflag;

**

Upvotes: 0

Views: 49

Answers (2)

phponwebsites
phponwebsites

Reputation: 671

Try this method,

   $name = $_SESSION['sess_user'];
   $q = mysql_query("select flag from members where user='".$name."' ") or die(mysql_error());
   $res = mysql_fetch_assoc($q);
   $flag = $res['flag'];

You can use mysql_fetch_assoc() to retrieve filed from database here. Reference: here

Upvotes: 0

user1646111
user1646111

Reputation:

You need to use mysql_fetch_array() or mysql_fetch_assoc()

$resultflag = mysql_query($queryflag) or die(mysql_error());
while ($row = mysql_fetch_assoc($resultflag)) {
  print_r($row)
}

Please note that mysql_* functions were deprecated, you need to switch to PDO or MySQLI

Upvotes: 1

Related Questions