CodeIgniter Forums
Spot my Query error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Spot my Query error (/thread-2778.html)



Spot my Query error - El Forum - 08-23-2007

[eluser]Kemik[/eluser]
Hello,

Here's my code:
Code:
$query = "SELECT f.email, u.user_id
     FROM forgotten_password AS f
     LEFT JOIN users AS u ON f.email = u.email
     WHERE f.act_key = '$act_key'";
            
if ($query->num_rows() < 1) {
    show_error('Reset ID passed is not in the database');
}
            
$row = $query->row();
However I get "Call to a member function on a non-object" for the $query->num_rows().

Edit: Fixed - Add $query = $this->db->query($query); above the $query->num_rows() IF. I'm sure I did try that before but must have mistyped it.


Spot my Query error - El Forum - 08-23-2007

[eluser]coolfactor[/eluser]
You've composed a query string, but you haven't executed it to get back a query resultset.

Code:
$query = "SELECT f.email, u.user_id
     FROM forgotten_password AS f
     LEFT JOIN users AS u ON f.email = u.email
     WHERE f.act_key = '$act_key'";

$result = $this->db->query($query);    // <-- you need this or something like it.

if (!$result OR ($result->num_rows() < 1)) {
    show_error('Reset ID passed is not in the database');
}



Spot my Query error - El Forum - 08-23-2007

[eluser]coolfactor[/eluser]
Just a friendly note: Try to keep your development-focused questions in the "Code & Application Development" forum. The "CodeIgniter" forum should be used for discussions about CodeIgniter and its architecture.