我很难将多个下拉菜单选项添加到 MySQL 数据库。我从freezecoders.com获得了以下代码
<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=mysql_real_escape_string($_POST['game']);
$choice1=implode(',',$choice);
mysql_query("insert into tb values('','$choice1')");
}
?>
当我运行此代码时,我不断收到mysql_real_escape_string()
与 implode()
函数相关的错误消息。
The error message are "Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\WAMP\www\COSHH\test\index.php on line 8"
和
"Warning: implode() [function.implode]: Invalid arguments passed in C:\WAMP\www\COSHH\test\index.php on line 9"
不幸的是,我没有使用这些功能的经验。有人可以指出我这里出了什么问题吗?我正在使用WAMP (PHP 5.3.8)
和Google Chrome (Version 24.0.1312.52)