我有一个mysql表中的一系列复选框:
$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 '' . $strategyname;
}
?>
我希望能够将多个“策略”存储到“研究”表的每一行,因此我使用另一个表(sslink)来存储研究的id和策略的名称。这在一定程度上是因为“策略”的数量会越来越多,所以它们需要存储在数据库中。这是我当前使用的代码:
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 "Article '$title' updated";
$strategy = stripslashes($strategy);
}
?>
这是返回的错误:
注意:未定义的索引:strategy in/casestudyform.php第66行
错误:您的SQL语法有错误;请检查与MySQL服务器版本相对应的手册,在第1行的“study-id”,“strategyname”)值(“1”,“n;”)附近使用正确的语法
有人知道怎么解决这个问题吗?还是更好的方法?
提前谢谢!