我有一系列的复选框被出来一个MySQL表的:多个动态生成的复选框
<?php
$result = mysql_query("SELECT * FROM strategies");
if (!$result) {
die("Database query failed: " . mysql_error());
}
while($row = mysql_fetch_array($result)) {
$strategylist = $row['name'];
$strategyname = htmlspecialchars($row['name']);
echo '<input type="checkbox" name="strategy[]" value="' . $strategylist . '" />' . $strategyname;
}
?>
我希望能够存储多个“战略”到每一行上“学习”表,所以我正在使用另一个表(sslink)来存储研究的ID和策略的名称。这部分是因为会有越来越多的“策略”,所以他们需要存储在数据库中。这是我目前使用的代码:
<?php
if(isset($_POST['update1']))
{
$strategy=serialize($_POST['strategy']); //line 66, where the warning is happening
if(!get_magic_quotes_gpc())
{
$strategy = addslashes($strategy);
}
// update the article in the database
$query ="INSERT INTO sslink('study_id', 'strategyname') VALUES ('".$_GET['id']. "', '" .$strategy. "')";
mysql_query($query) or die('Error : ' . mysql_error());
$cacheDir = dirname(__FILE__) . '/cache/';
$cacheFile = $cacheDir . '_' . $_GET['id'] . '.html';
@unlink($cacheFile);
@unlink($cacheDir . 'index.html');
echo "<b>Article '$title' updated</b>";
$strategy = stripslashes($strategy);
}
?>
这是获取返回的错误:行66 错误策略/casestudyform.php:
公告:未定义的索引您有一个您的SQL语法错误;检查与你的MySQL服务器版本相对应的手册,在''study_id','strategyname'附近使用正确的语法)在第1行的VALUES('1','N;')'
有谁知道如何解决这个问题?或更好的方式来做到这一点?
在此先感谢!
在SQL中使用它们之前,请记住要转义$ _GET请求参数! – 2009-06-25 17:55:33