以下代码在数据库的单个单元格中存储选定的值,任何人都可以帮助我们如何存储多个单元格。谢谢
<html>
<body>
<form method="post" action="index.php">
Select your favourite game:<br/>
<select name="game[]" multiple="multiple">
<option>Football</option>
<option>Volleyball</option>
<option>Badminton</option>
<option>Cricket</option>
</select>
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$query=mysql_connect('localhost','root','');
mysql_select_db("freeze",$query);
$choice=implode(',',$_POST['game']);
$choice1=mysql_real_escape_string($choice);
mysql_query("insert into tb values('','$choice1')");
}
?>
答案 0 :(得分:0)
使用基本INSERT query。
例如,更改:
insert into tb values('','$choice1')
类似于:
INSERT INTO TB (col1, col2, col3) VALUES ('$choice1', '$choice2', '$choice3')