Here is my code, I am trying to add multi items in database, in these 5 items my one item is default, when I am checked on Item no 3, In database item 3 value save as 0 and 1st item value save as 1.
This is not correct, I want that when Item 3 is checked than after submit form than in database Item 3 save as 1 else save value 0.
Please any one tell me how to this work
<?php
if (isset($_POST['action'])) {
$prods = count($_POST['prod']);
for ($i = 0; $i < $prods; $i++) {
$prod = $_POST['prod'][$i];
$default = (!empty($_POST['is'][$i])) ? 1 : 0;
mysql_query("INSERT INTO `items` (`prod`, `is_default`)VALUES('{$prod}', '{$default}')");
}
}
?>
<form action="" method="post">
<input type="hidden" name="action" value="add">
<span>Item Name</span> <span style="padding-left:100px">Is default</span> <br>
<input type="text" name="prod[]" value="">
<input type="radio" name="is[]" value="1">Item 1<br>
<input type="text" name="prod[]" value="">
<input type="radio" name="is[]" value="1">Item 2<br>
<input type="text" name="prod[]" value="">
<input type="radio" name="is[]" value="1">Item 3<br>
<input type="text" name="prod[]" value="">
<input type="radio" name="is[]" value="1">Item 4<br>
<input type="text" name="prod[]" value="">
<input type="radio" name="is[]" value="1">Item 5<br>
<input type="submit" value="Save">
</form>