-2
function add_member($idmembers, $firstname, $lastname,  $email, $phone, $level, $password) {
global $db;
$query = "INSERT INTO members
             (idmembers,  first, last, email, phone, level, password)
          VALUES
                ($idmembers,  '$firstname', '$lastname', '$email', '$phone', '$level', '$password')";
var_dump($query);
$db->exec($query);

}

This code gives me this error and information from the var dump:

string(224) "INSERT INTO members (idmembers, first, last, email, phone, level, password) VALUES (, 'Gina', 'Hill', 'hill@me.com', '7778889898', 'm', '803591803e3d6e646cd3ee4a35fee6dd')" Fatal error: Call to a member function exec() on null in J:\XAMPP\htdocs\WEBSITE\register.php on line 26

I've checked adding the query to the database to make sure the query is working and it works fine.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

2

I suspect that $db is either not an object (if it's not actually NULL), or $db doesn't have a function named exec.

I recommend you verify that your connection to the database is successful, and verify that $db is the connection object. Verify that exec is a valid function for the object.

Also, your code appears to be vulnerable to SQL Injection. (We don't see that the arguments passed to the function have been "escaped" to be safe for inclusion in SQL text.) We much prefer to see a prepared statements with bind placeholders.

spencer7593
  • 106,611
  • 15
  • 112
  • 140
  • Thank you, but I'm not sure what I can change to get this to work from this answer. I am in a development environment with this code and hope that you realize it isn't he finished product. Thank you, but please tell me what you mean for me to change to get the code to work. – Regina Shepherd Riddle Feb 11 '15 at 06:56