3

I'm getting the error:

Notice: Trying to get property of non-object.

I've been looking into this for a while now and wasn't able to find what's wrong with it, I tried some different ways of syntax(with [''] and things like this), but so far without success. I also watched a lot of old questions on SO but they didn't help me either.

My guess would be something is wrong in my query, because if I echo the result before the num_rows, it shows me nothing.

$dbhandle = new mysqli($hostdb, $userdb, $passdb, $namedb);

if ($dbhandle->connect_error) {
  exit("There was an error with your connection: ".$dbhandle->connect_error);
}

$result6 = $dbhandle->query("SELECT * FROM email WHERE group= 'groupname' ");
$row_cnt6 = $result6->num_rows;

I hope you can help me out.

Oldskool
  • 33,525
  • 7
  • 51
  • 64
marijn
  • 560
  • 3
  • 22

1 Answers1

4

GROUP is reserved keyword in mysql in must be in backtick

Change this to

SELECT * FROM email WHERE group= 'groupname' 

To

SELECT * FROM email WHERE `group`= 'groupname'

Check list https://dev.mysql.com/doc/refman/5.7/en/keywords.html

To check error in your mysqli quesry use

if (!$mysqli->query("YOUR QUERY")) {
    printf("Errormessage: %s\n", $mysqli->error);
}

Read http://php.net/manual/en/mysqli.error.php

Don't pass directly value to column use mysqli prepare statement

http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

Saty
  • 22,213
  • 7
  • 30
  • 49