-1
public function query($sql, $params = array()){
        $this->_error = false;
        if(this->_query = $this->_pdo->prepare($sql)){
            $x = 1;
            if(count($params)){
                foreach($params as $param){
                    $this->_query->bindValue($x, $param);
                    $x++;
                }
            }

            if($this->_query->execute()){
                echo "Success";
            }
        }
    }

I get the following error althought i think all is being done correctly. I pray I get some direction as to what am doing wrong.

Ismail Yushaw
  • 131
  • 1
  • 4

1 Answers1

2

The issue is on the third line:

if(this->_query

Should be:

if($this->_query

Remember your variables must be prefixed with the dollar sign.

Also, when you see a Parse Error, keep in mind it may have nothing to do with the thing it tells you (the -> for example), rather it is something before that, which makes it unable to parse the statement correctly.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • 1
    Trivial typos like this don't deserve real answers, just post a comment and vote to close. – Barmar Aug 31 '16 at 16:54
  • 1
    It's not like he doesn't know that variables require `$`, since he did it right all the other places in the function. This was just a typo. – Barmar Aug 31 '16 at 16:55
  • Yeah, but when I look at the other related questions, they are all over the place on what the actual issue is. If this helps somebody in the future to double check the dollar sign on their variables, it may be worth it. – Jeremy Harris Aug 31 '16 at 16:56
  • Wow you down vote because someone put in a typo? That happens to me all the time. I think it's a well thought out question with a small little problem that neeeded others to fix. I do wish he listed the line # (PHP usually throws a line number right?) – Forbs Aug 31 '16 at 16:56
  • It worked... I have to pay attention to the difference between the two – Ismail Yushaw Aug 31 '16 at 16:58