I have tried searching the forumn but could not fix my fatal error when coding my php prepared statement.

Im using a prepared statement to prevent sql injection and also prevent error when user inputs apostrophe. Below is my code:

submit\_data.php

```
<?php
include "../connect.php";

$message_form = $_POST['message'];
$username_form = $_POST['user'];

// $insert_data=$db->query("INSERT INTO test_table_1(message,user) VALUES ('$message_form','$username_form')");

$insert_data=$db->prepare("INSERT INTO test_table_1(message,user) VALUES (?, ?)");

$insert_data->bind_param("ss", $message_form, $username_form);
$insert_data->execute();

if ($insert_data === TRUE ){
    echo "New record created successfully";

} else {
    echo "Error: " . $insert_data . "<br>" . $db->error;
  }

$insert_data->close();
$db->close();
?>

```

my connection file to the database( connect.php)

```
<?php

            $host = "localhost";
            $user = "root";
            $pass = ""; 

            $database_name = "test"; 
            $table_name = "test_table_1";  

            //connect to mysql database
            $db = new mysqli($host, $user, $pass, $database_name); 
            //check connection
            if ($db -> connect_error) {
                die("error mysql database not connected: " . $db -> connect_error);
            }
            // else {
            //  echo "connected successfully" ; //enable this for debugging purpose 
            // }            

?>  

```

This is the error i am receiving

> 
> **Catchable fatal error**:  
> 
>  Object of class mysqli\_stmt could not be converted to string in **/Applications/XAMPP/xamppfiles/htdocs/z\_admin/submit\_data.php**
>  on line **19**  
> 
> 
> 
> 

Any help or pointers will be greatly appreciated. Thank you