的index.php
<!DOCTYPE html>
</html>
<body>
<form name="fruits" action="selectexec.php" method="post">
<select name="department">
<option value="apple">apple</option>
<option value="mango">mango</option>
<option value="orange">orange</option>
</select>
<select name="company">
<option value="ASUS">ASUS</option>
<option value="LENOVO">LENOVO</option>
<option value="ACER">ACER</option>
</select>
<input type="submit" name="submit" />
</form>
</body>
</html>
selectexe.php
<?php
include_once('pdo-connect.php');
if(isset($_POST['submit'])){
$department=$_POST['department'];
$company=$_POST['company'];
// SQL statements
$sql = "INSERT INTO selectformtbl (department,company)values('$department',$company)";
$db->exec($sql);
}
?>
答案 0 :(得分:0)
<select>
代码应具有multiple
属性。
<select name="department[]" multiple></select>
<select name="company[]" multiple></select>
在PHP中,您可以内插所有这些值并直接存储到数据库。
$departments = implode($_POST['department']);
$company = implode($_POST['company']);
$sql = "INSERT INTO selectformtbl (`department`,`company`) values ('$department','$company')";
$db->exec($sql);