• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROBLEM WITH DB QUERIES

#1
[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?!?!?!?!?!?!?!?

#2
[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.

#3
[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');

#4
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.