下面的代码将选择的值存储在数据库的单个单元格中,谁能帮助我们如何在多个单元格中存储。谢谢
<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')");
}
?>
使用基本的INSERT查询。
例如:
insert into tb values('','$choice1')
转到如下:
INSERT INTO TB (col1, col2, col3) VALUES ('$choice1', '$choice2', '$choice3')