CodeIgniter Forums
PROBLEM WITH DB QUERIES - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: PROBLEM WITH DB QUERIES (/thread-2142.html)



PROBLEM WITH DB QUERIES - El Forum - 07-18-2007

[eluser]ReSTe[/eluser]
Hi all, i'm newbie about codeigniter, i'm developing an application for my 3rd year thesis at politecnico Milano... i have a question:

here is my code:

$user=$_POST["user"];
$pass=$_POST["password"];
$query = "select * from operatore where user='$user' and password= '$pass'";
$result=$this->db->query($query);
//echo "$query[nome]";
if($result->num_rows() > 0)
echo"ASDASD";


and i see this error:

Fatal error: Call to a member function num_rows() on a non-object in C:\www\codeigniter\CodeIgniter_1.5.4\system\application\controllers\tmfmagenta.php on line 31

(it's on $result variable)


WHY?!?!?!?!?!?!?!?


PROBLEM WITH DB QUERIES - El Forum - 07-18-2007

[eluser]batteries[/eluser]
try this:

Code:
$query = “select * from operatore where user = ? and password = ?”;
$result = $this->db->query($query, array($user, $pass));

if($result->num_rows() > 0)
    echo"ASDASD";

if that doesn't work then there is probably something wrong with the query, or your table schema.


PROBLEM WITH DB QUERIES - El Forum - 07-18-2007

[eluser]Aaron L.[/eluser]
I recommend using the Active Record library which is built into CI. Try this:
Code:
$this->db->where('user',$user);
$this->db->where('password',$pass);
$result = $this->db->get('operatore');



PROBLEM WITH DB QUERIES - El Forum - 07-19-2007

[eluser]ReSTe[/eluser]
hi! thanks to all, i solved the problem... it was simply a DB-connection problem Smile


again, thanks a lot Wink

Matteo.