title: Insert multiple data if not exists or update data (php/mysql)
body: <p>I want to insert multiple data to mysql.
  My PHP code which is Array input field:</p>
  
  <p>pag1.php</p>
  
  <pre><code>  &lt;form method="post" action="page2.php"&gt;
       &lt;input type="text" name="option_id[]" size="1"&gt;
       &lt;input type="text" name="store_id[]" size="1"&gt;
       &lt;button type="submit" name="action" value="add" &gt;Add&lt;/button&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>page2.php</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['action'])){
  
  for ($i=0; $i &lt; count($_POST['option_id']); $i++ ) {
  $option_id = $_POST['option_id'][$i];
  $store_id = $_POST['store_id'][$i];
  // check if option id is exists or not 
           $result = mysql_query ("SELECT * FROM temp_cart WHERE option_id='$option_id' AND store_id='$store_id' ") or die (mysql_error());
  
           if (mysql_num_rows($result) == 0){
                       //insert query 
                   }
                   else {
                       //update query
                   }
          }
  }
  ?&gt;
  </code></pre>
  
  <p>For loop is not work.</p>
  
  <p>Your help would be very much appreciated. </p>