When you have after the name of an input in the form, what is being passed for each name is an array.
If you added this to the top of your page
echo "<pre>";
print_r($_POST);
echo "</pre>";
You would see that this array like so.
Array
(
[language] => Array
(
[0] => Pashto
)
[reading] => Array
(
[0] => good
)
[speaking] => Array
(
[0] => excellent
)
[writing] => Array
(
[0] => fair
)
[submit] => Submit
)
Notice that the array key is zero in this example. If you were looping those form inputs, with each loop the key would go up incrementally, 1,2,3 etc.
For processing, you can get the values of each of these by using a foreach statement and using the same key to build a values array that could then be used to insert into database.
foreach($_POST['language'] as $key => $language){
$reading = $_POST['reading'][$key];
$speaking = $_POST['speaking'][$key];
$writing = $_POST['writing'][$key];
$values[] = "('$language','$reading','$speaking','$writing')";
}
You can then implode this values array like so.
$sql = "INSERT INTO `jobs`.`languages` (
`language` ,
`reading` ,
`speaking` ,
`writing`
)
VALUES ";
$sql .= implode(",",$values);
// Test
echo "<br />$sql<br />";
Here’s the complete test page.
<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
foreach($_POST['language'] as $key => $language){
$reading = $_POST['reading'][$key];
$speaking = $_POST['speaking'][$key];
$writing = $_POST['writing'][$key];
$values[] = "('$language','$reading','$speaking','$writing')";
}
$sql = "INSERT INTO `jobs`.`languages` (
`language` ,
`reading` ,
`speaking` ,
`writing`
)
VALUES ";
$sql .= implode(",",$values);
// Test
echo "<br />$sql<br />";
?>
<html>
<body>
<form action="" method="post">
<label for="lang_eng2">Pashto:
<input name="language[]" type="hidden" id="language[]" value="Pashto" />
</label>
<select name="reading[]" id="reading[]">
<option value="fair">Fair</option>
<option value="good" selected="selected">Good</option>
<option value="excellent">Excellent</option>
</select>
<select name="speaking[]" id="speaking[]">
<option value="fair">Fair</option>
<option value="good" selected="selected">Good</option>
<option value="excellent">Excellent</option>
</select>
<select name="writing[]" id="writing[]">
<option value="fair">Fair</option>
<option value="good" selected="selected">Good</option>
<option value="excellent">Excellent</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>