Reputation: 74
** Following query executes properly and gives exact result for login. But when I trying to access fields returned from the query, it shows me null. In below code, I've checked for correct email id and my column name is 'user_email', it validates the user login correctly, but when I was trying to access the same email id from returned result($checkLogin->user_email), it gives me null **
$checkLogin=$db->query("SELECT * from `users` where
`user_email`='$u_email' and `user_password`='$u_password'");
if($checkLogin)
{
$data[]=array(
'status'=>'success',
'email'=>$u_email,
'pass'=>$u_password,
'email1'=>$checkLogin->user_email
);
}
Please give me solution over this
Upvotes: 0
Views: 168
Reputation: 509
The query() function returns a result object. You need to fetch your result. There are a lot of functions for this: fetch_row(), fetch_assoc(), fetch_array(), fetch_all(). You can find examples of how to use those at php.net.
You could for example write the following:
$checkLogin = $db->query("SELECT * from `users` where `user_email`='$u_email' and `user_password`='$u_password'");
if($row = $checkLogin->fetch_object())
{
echo $row->user_email;
}
Upvotes: 2
Reputation: 74
I found the Solution. I've to use $db->get_row instead of $db->query as follows
$checkLogin=$db->get_row("SELECT * from `users` where `user_email`='$u_email' and `user_password`='$u_password'");
if($checkLogin)
{
$data[]=array(
'status'=>'success',
'email'=>$u_email,
'pass'=>$u_password,
'email1'=>$checkLogin->user_email
);
}
Upvotes: 0