title: Integrity constraint violation PDO method (create query) php
body: <p>I have 3 tables which is subcategory, product, and prod_category.</p>
  
  <p>When I create my product, if it successful, it will return the successfull product_id, after that it will capture the form subcategory column ,to carry out the next query which insert product_id and subcategory_id to the prod_category table. I tested out in a single php file to test the whether the function is working. It can insert, but when I fit into my situation, it was giving me this error.</p>
  
  <blockquote>
    <p>Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (<code>yokotachi</code>.<code>prod_category</code>, CONSTRAINT <code>prod_category_ibfk_4</code> FOREIGN KEY (<code>product_id</code>) REFERENCES <code>product</code> (<code>product_id</code>) ON DELETE CASCADE ON UPDATE CASCADE) in C:\xampp\htdocs\yokotachi\models\Prod_category.php on line 27</p>
  </blockquote>
  
  <p>I confirm that, 2 parameter was passed into the function, but i dont know why it cannot perform the query.</p>
  
  <pre><code>if($_POST){ 
  $title = mysql_real_escape_string($_POST['title']);
  $model = mysql_real_escape_string($_POST['model']);
  $description = stripslashes($_POST['description']);
  $feature = stripslashes($_POST['feature']);
  $specification = stripslashes($_POST['specification']); 
  
  $subcategory_name = mysql_real_escape_string($_POST['product_subcategory']);
  
  $sub_obj = $subcategory-&gt;find_by_sub_category_name($subcategory_name);
  
  $subcategory_id = $sub_obj-&gt;sub_category_id;
  echo $subcategory_id;
  $executed_product_id=
      $product-&gt;create($title,$model,$description,$feature,$specification);
  echo "im here".$subcategory_id;
  echo $executed_product_id;
  $responde = $prod_category-&gt;create($executed_product_id,$subcategory_id);
  if($responde){
      echo "&lt;script&gt;";
      echo "alert(".$executed_product_id.");";
      echo "&lt;/script&gt;";
      header("location: ../../../views/admin/product/product_index.php");
  }}
  </code></pre>
  
  <p>i did saw 1 post is reindex problem, and asked to truncate the table. But I have no idea , how to perform the truncate query in my situation.</p>
  
  <p>Thanks in advance.</p>