Jump to content

object of class MySqli cannot be converted to string


jimfog

Recommended Posts

I am trying to run a query and I get the above error.

Usually, and as far as I know. the above error appear when you are trying to get something out of the db.

 

Here I am just trying to insert data coming from a form with the POST method.

Here is the function that tries to make the insertion-it is for registering a user to the site.

function register_enduser($post,$connection)        {           $name = $connection->real_escape_string($_POST['name']);     $lastname = $connection->real_escape_string($_POST['lastname']);     $email = $connection->real_escape_string($_POST['e-mail']);     $pass_hashed = password::hash($_POST['password']);      $passwd = $connection->real_escape_string( $pass_hashed);     $usertype= $_POST['usertype'];//     dump($post);     $connection->set_charset("utf8");     $result = $connection->query("select * from users where email='" . $email . "'");     if (!$result) {         throw new Exception('Error');         return false;     }     elseif ($result->num_rows > 0) {         $errorclass['existentemail'] = 'There is already such an email.';         return false;     } else {         $result1 = $connection->query("insert into users values         (NULL,'".$name."','".$lastname ."','".$email."','".$passwd."','".$pass_hashed. "', '".$usertype. "')")or die($connection);     }     if (!$result1) {         throw new Exception('error.');         return false;     }      return true; }

The error appear in the $result1 query, the second query performed, not the first one.

Link to comment
Share on other sites

forget it...I found it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...