Your form could be better constructed. As it is currently constructed, the page that this form submits to (insert.php) must somehow guess how many records there are. You could add a hidden input to your form that says there are 3 records, or the insert.php page could check to see how big one of the four arrays is:
$num_records = count($_POST['language']); // or you could check room, name, voucher
Once you know how many records there are, you can loop and create a mysql statement for each record:
EDIT: updated this code with a little more detail
$num_records = count($_POST['language']); // this assumes that room, name, voucher all have the same number of items and the items much up in a one-to-one fashion
// connect to the db
mysql_connect ('my.mysql.server.mydomain.com', 'username', 'password')
or die ('could not connect!');
mysql_select_db('my_database')
or die ('could not select db');
for($i=0; $i<$num_records; $i++) {
$sql = "INSERT INTO some_table (language, room, name, voucher) VALUES (
'" . mysql_real_escape_string($_POST['language'][$i]) . "',
'" . mysql_real_escape_string($_POST['room'][$i]) . "',
'" . mysql_real_escape_string($_POST['name'][$i]) . "',
'" . mysql_real_escape_string($_POST['voucher'][$i]) . "'
)";
// do the query
mysql_query($sql)
or die('query failed:' . mysql_error());
}
IMPORTANT: The code I just wrote there doesn't do any validation on your data so some mean-spirited visitor might insert all kinds of bogus garbage in your database. You should really check all the values to make sure they are ok. Something like this before you start inserting anything:
$valid_languages = array('english', 'french', 'spanish');
foreach($_POST['language'] as $lang) {
// this comparison is case-sensitive so while english works, ENGLISH will not
if (!in_array($lang, $valid_languages)) {
die($lang . ' IS NOT A VALID LANGUAGE');
}
}
You should always validate input from a form or you are just asking for trouble from the h4xorz