0

I want to prevent injection on my codeigniter script. I used Query Binding array, but It's not fetching out the result... I get this error

Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs

code bellow

<php
$my = "Select * from gw_marge where amount != ? AND is_activated= ? ORDER BY RAND()";
$this->db->query($my, array(0, 1));
      foreach ($my->result() as $roww)
    {
    $pay = $roww->amount;
    $idd = $roww->id;
  }
 ?>
<p><?php echo $pay.' &'.$idd; ?></p>

Where did i get it wrong.

7
  • is this solved ?? Commented Mar 29, 2017 at 18:02
  • Not solved yet... i get error. Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs Commented Mar 29, 2017 at 18:03
  • Is this code in Model or controller ?? Commented Mar 29, 2017 at 18:04
  • I have it in view Commented Mar 29, 2017 at 18:05
  • its wrong then. Add your controller as well Commented Mar 29, 2017 at 18:06

1 Answer 1

1

Change

$this->db->query($my, array(0, 1));
foreach ($my->result() as $roww)

to

$query = $this->db->query($my, array(0, 1));
foreach ($query->result() as $roww)
Sign up to request clarification or add additional context in comments.

2 Comments

without giving(wrong) solution it's better to tell him why we use MVC. check this comment as well
@AbdullaNilam, You are correct that his approach is not good MVC. But the question was "why do I get this error" and not "what's wrong with my MVC use." But the real reason I did not comment on MVC is that it wasn't known that his code was in the view until after I posted the answer. You've got the reputation to edit my answer - go ahead and explain the proper MVC structure. (I would, but must go back to work)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.