Im having a problem using foreach i cant seem to understand this yet.
my problem is when i enter all the data needed it shows many inserting code
I cant seem to figure this out
This is the Output
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (1,1)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (1,2)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (1,3)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (1,4)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (2,1)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (2,2)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (2,3)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (2,4)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (3,1)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (3,2)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (3,3)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (3,4)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (4,1)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (4,2)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (4,3)
INSERT INTO `dependents`(`d_name`, `d_age`) VALUES (4,4)
This is the code
<?php
$dependents = $_POST['dependentsname'];
$age = $_POST['age'];
foreach ($dependents as $key1 => $value1){
// $value =$dependents[$key1];
foreach ($age as $key2 => $value2){
echo $insert_dependents="INSERT INTO `dependents`(`d_name`, `d_age`)
VALUES ($value1,$value2)";
echo "<br>";
}
echo "<br>";
}
?>
<div id="Dependents_left">
<u>DEPENDENTS:</u>
<table>
<tr>
<th>NAME</th>
<th>AGE</th>
<th>NAME</th>
<th>AGE</th>
</tr>
<tr>
<td>1. <input type="text" name="dependentsname[]"></td>
<td><input type="text" name="age[]"></td>
<td>3. <input type="text" name="dependentsname[]"></td>
<td><input type="text" name="age[]"></td>
</tr>
<tr>
<td>2. <input type="text" name="dependentsname[]"></td>
<td><input type="text" name="age[]"></td>
<td>4. <input type="text" name="dependentsname[]"></td>
<td><input type="text" name="age[]"></td>
</tr>
</table>
any help would be helpful