0

I am trying to put values inside my database but i am not able to achieve through this as i am getting an error constantly .

ERROR: Call to a member function fetch_object() on a non-object

Code:

require '../connect.inc.php';
$result = $mysqli->query("SELECT COUNT(user_email) as usercount FROM registered_users WHERE user_email=$email");     
$user_count = $result->fetch_object()->usercount; //will return 0 if user doesn't exist

connect.inc.php connects to the database.Above code throws an error at usercount.

My question is what is am i doing wrong ?

Note : It has been marked as duplicate for this question When to use single quotes, double quotes, and backticks in MySQL but i don't think it has any problem in quotes and backticks.

Community
  • 1
  • 1
  • Lovely [sql injection attack](http://bobby-tables.com) vulnerability. Enjoy having your server pwn3d. – Marc B Jan 12 '16 at 15:18
  • @MarcB i know that just answer the question if you know what the problem is . –  Jan 12 '16 at 15:20
  • 2
    uh, yes, the problem is quotes. look at the query you're building. do you really think there's a field named `president@whitehouse.gov` in your database? `'president@whitehouse.gov'` and `president@whitehouse.gov` are two entirely different things to an SQL parser... – Marc B Jan 12 '16 at 15:21
  • oh , could you please tell me the final query that i should use ? @MarcB –  Jan 12 '16 at 15:23
  • not really. you just need to read the linked duplicate. giving you the answer would be futile, as you'd learn nothing. – Marc B Jan 12 '16 at 15:24
  • okay i read and tried but still didnt work out @MarcB –  Jan 12 '16 at 15:57
  • same error as before –  Jan 12 '16 at 16:00
  • then start writing proper code, and **NOT** assuming nothing would ever fail. `$res = mysqli_query(...); if (!$res) { die(mysqli_error(...)); }`. etc.... – Marc B Jan 12 '16 at 16:01

0 Answers0