Reputation: 11
I'm getting the following error:
Catchable fatal error: Object of class stdClass could not be converted to string
I am using php5.5.34.
My code is as follows:
<?php
if($queryaddress_select_user_basic_info = $db->query("SELECT * FROM user_basic_info WHERE username = '$valusername_registerphp'"))
{
if($count = $queryaddress_select_user_basic_info->num_rows)
{
while($valuesinloop_userbasicinfo = $queryaddress_select_user_basic_info->fetch_object())
{
echo $valuesinloop_userbasicinfo->username,'<br>';
echo $_SESSION['user_primaryvalue'] =$valuesinloop_userbasicinfo; //error is on this line
}
}
else
{
echo "cannot count results/cannot return results";
}
}
else
{
echo "query not written correctly!";
}
?>
Any ideas why it's throwing an error?
Upvotes: 1
Views: 4327
Reputation: 2395
$valuesinloop_userbasicinfo
is an object. You're setting the value of a session to that object (which works fine) but do mind that setting a variable will also return its value.
echo $_SESSION['user_primaryvalue'] =$valuesinloop_userbasicinfo;
This line will not only set the value of $_SESSION['user_primaryvalue']
but also echo
it and considering $_SESSION['user_primaryvalue']
is now an object it will cause the given error.
Upvotes: 0