<input name="names[]" type="text"/><select><option value="male">male</option><option value="female">female</option></select>
<input name="names[]" type="text"/><select><option value="male">male</option><option value="female">female</option></select>
<input name="names[]" type="text"/><select><option value="male">male</option><option value="female">female</option></select>
if (!empty($_POST['names'])) {
foreach ($_POST['names'] AS $names) {
// add to the database
if (!empty($names)){
$rs=mysql_query("SELECT names FROM table WHERE names = '$names' LIMIT 1");
if(mysql_num_rows($rs) == 0) {
mysql_query("INSERT INTO table (names,gender) VALUES ('$names','$gender')");
}
}
}
}
This does inset the names however i don’t know how i can make the genders work for each individual name.
You need to give your SELECT elements a name:
Now you can use the key of
$_POST['names']to get the corresponding gender:You should also use
mysql_real_escape_stringto sanatize the data sent by the user.