title: How Can i solved this error:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '30' for key 'PRIMARY'
body: <p>I am facing an issue when inserting values from a form into my mysql -<code>table item_image</code>- with the -<code>lastInsertId()</code>- </p>
  
  <p><strong>Here is my db</strong></p>
  
  <pre><code>item table
  id(auto increment,Primary key)
  item_name (varchar)
  item_description (tinytext)
  item_price(varchar)
  item_date(date)
  
  item_image
  itemId(PRIMARY KEY),
  small_image(varchar),
  big_image(varchar)
  </code></pre>
  
  <p>HERE IS MY FORM</p>
  
  <pre><code>&lt;form method="post" action="?&lt;?php echo $action;?&gt;"&gt;
  &lt;p&gt;
  &lt;label for="item_name"&gt;Name of Article :&lt;/label&gt;
  &lt;input type="text" name="item_name" id="item_name" value="" /&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
  &lt;label for="item_description"&gt;Short Description:&lt;/label&gt;
  &lt;textarea id="item_description" name="item_description" rows="3" cols="40" value=""&gt;&lt;/textarea&gt;
   &lt;/p&gt;
  
  &lt;p&gt;
  &lt;label for=""&gt;Item small Image :&lt;/label&gt;
  &lt;input type="text" id="small_image" name="addimages[]" value="" /&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
  &lt;label for=""&gt;Item small Image:&lt;/label&gt;
  &lt;input type="text" id="big_image" name="addimages[]" value="" /&gt;
  &lt;/p&gt;
  
  &lt;div&gt;
  &lt;input type="submit" name="submit" id="submit" value="&lt;?php echo $button;?&gt;" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>AND DOWN HERE WE HAVE THE PHP CODE</strong> </p>
  
  <pre><code>if (isset($_GET['addform'])) {
  $item_name = trim($_POST['item_name']);
  $item_description = trim($_POST['item_description']);
  $item_price = trim($_POST['item_price']);
  
   try {
  
  $sql = 'INSERT INTO items SET 
          item_name = :item_name,
          item_description = :item_description,
          item_price = :item_price,
          item_date= CURDATE()';
  $stmt = $pdo-&gt;prepare($sql);
  $stmt-&gt;bindValue(':item_name', $item_name);
  $stmt-&gt;bindValue(':item_description', $item_description);
  $stmt-&gt;bindValue(':item_price', $item_price);
  $stmt-&gt;execute();
   } 
    catch (PDOException $e) {
     echo "Something went wrong".$e-&gt;getMessage();
   }
  
  $itemId = $pdo-&gt;lastInsertId(); 
  
    if (isset($_POST['addimages'])) {
  
      $add_images = $_POST['addimages'];
  
      try {
        $sql ='INSERT INTO item_image SET
                itemId = :itemId,
               small_image = :small_image,
               big_image = :big_image';
        $stmt = $pdo-&gt;prepare($sql);
           foreach ($add_images as $add_image) {
             $stmt-&gt;bindValue(':itemId', $itemId);
             $stmt-&gt;bindValue(':small_image', $add_image[0]);
             $stmt-&gt;bindValue(':big_image', $add_image[1]);
             $stmt-&gt;execute();
           }
      }   
        catch (PDOException $e) {
        echo "Sth got wrong with the query".$e-&gt;getMessage();
      }
    }
  </code></pre>
  
  <p>The issue i am having is : All the values got insert in items table, but for the item_image table...i am having this error :</p>
  
  <p><code>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '30' for key 'PRIMARY</code>' </p>
  
  <p>I am having searching, but cannot find the issue..my foreach loop seems to be correct..</p>
  
  <p>I am trying to is to do is to: insert the <code>lastInsertId()</code> value and <code>addimages array values</code> into my <strong>item_image</strong> table</p>
  
  <p>Can sombody help out..Thanks.</p>