我有一系列的複選框被出來一個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