1

Here, I am getting error like,

Notice: Trying to get property of non-object

in last two lines while fetching record. what does it say? My code:

$Id = $_REQUEST['id'];

        $sql = "Select * From ".CHANNEL_MASTER." 
                    Where sam_status = '".ACTIVE_STATUS."' And user_id = '".$_SESSION['user_id']."' And sam_id = '".$Id."'";

        $db->query($sql);
        $row = $db->fetch_object(MYSQL_FETCH_SINGLE);

        $siteID = array_search($row->sam_site_id, $site_id_array);
        $ebay_token = $row->sam_ebay_token;
Saty
  • 22,443
  • 7
  • 33
  • 51
Viral Bhoot
  • 357
  • 3
  • 17
  • 1
    Possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – vascowhite Nov 16 '15 at 07:31
  • You haven't initiated your database class. I'm not sure but I think you are either trying to use `mysqli` or `PDO`. – Peter Nov 16 '15 at 07:37

2 Answers2

0

You need to store query result into a variable then fetch data from it.

So instead of

 $db->query($sql);
 $row = $db->fetch_object(MYSQL_FETCH_SINGLE);

use

 $result=$db->query($sql);// store query result into $result
 $row = $result->fetch_object(MYSQL_FETCH_SINGLE);// fetch data from $result
Saty
  • 22,443
  • 7
  • 33
  • 51
0
$Id = $_REQUEST['id'];

        $sql = "Select * From ".CHANNEL_MASTER." 
                    Where sam_status = '".ACTIVE_STATUS."' And user_id = '".$_SESSION['user_id']."' And sam_id = '".$Id."'";

        $result = $db->query($sql);
        $row = $result->fetch_object(MYSQL_FETCH_SINGLE);

        $siteID = array_search($row->sam_site_id, $site_id_array);
        $ebay_token = $row->sam_ebay_token;
Parth Chavda
  • 1,819
  • 1
  • 23
  • 30