title: prepare statement for insert in php failed in my case
body: <p>I am using ajax and I can't tell what the error is, but I am certain that the data has been inserted in my database. Here is what I tried:</p>
  
  <pre><code>if(isset($_POST['user_id']) &amp;&amp; isset($_POST['content']) &amp;&amp; isset($_POST['date']) &amp;&amp; isset($_POST['category_id'])){
  
      $content = $_POST['content'];
      $date = $_POST['date'];
      $user_id = $_POST['user_id'];
      $category_id = $_POST['category_id'];
  
      $stmt = $db-&gt;prepare("INSERT INTO post_items(`post_id`,`content`,`date`,`user_id`,`category_id`) 
          VALUES (?,?,?,?)");
      $stmt = bind_param('ssii',$content,$date,$user_id,$category_id);
  
      if($stmt-&gt;execute()) { 
          echo mysqli_insert_id($db);
  
      }else{
          echo "Something is wrong. Insert failed..";
      }
  }
  </code></pre>
  
  <p>My old working version (with the lack of security) is shown below:</p>
  
  <pre><code>if(isset($_POST['user_id']) &amp;&amp; isset($_POST['content']) &amp;&amp; isset($_POST['date']) &amp;&amp; isset($_POST['category_id'])){
  
      $content = $_POST['content'];
      $date = $_POST['date'];
      $user_id = $_POST['user_id'];
      $category_id = $_POST['category_id'];
  
  /*  $result = $db-&gt;query("INSERT INTO post_items(`content`,`date`,`user_id`,`category_id`) 
          VALUES (".$content."', '".$date."', '".$user_id."', '".$category_id."')");*/
  
      $stmt = $db-&gt;prepare("INSERT INTO post_items(`post_id`,`content`,`date`,`user_id`,`category_id`) 
          VALUES (?,?,?,?)");
      $stmt = bind_param('ssii',$content,$date,$user_id,$category_id);
  
      if($stmt-&gt;execute()) { 
          echo mysqli_insert_id($db);
  
      }else{
          echo "Something is wrong. Insert failed..";
      }
  }
  </code></pre>
  
  <p>I am not sure what I did wrong here as it is the first time that I have worked with this material.</p>