I want to insert multiple data to mysql. My PHP code which is Array input field:
pag1.php
<form method="post" action="page2.php">
<input type="text" name="option_id[]" size="1">
<input type="text" name="store_id[]" size="1">
<button type="submit" name="action" value="add" >Add</button>
</form>
page2.php
<?php
if(isset($_POST['action'])){
for ($i=0; $i < 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
}
}
}
?>
For loop is not work.
Your help would be very much appreciated.