好吧,当我尝试使用MySQL信息填充下拉列表时,我遇到了问题。问题发生在第二次下拉时我试图从撇号的东西中获取信息......例如女士服装或男士服装。非常感谢任何帮助。
以下是错误:您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第1行的“服装”附近使用正确的语法
这是代码。
<?php
//**************************************
// Page load dropdown results //
//**************************************
function getTierOne()
{
$catresult = mysql_query("SELECT DISTINCT category FROM categories")
or die(mysql_error());
while($tier = mysql_fetch_array( $catresult ))
{
echo '<option value="'.$tier['category'].'">'.$tier['category'].'</option>';
}
}
//**************************************
// First selection results //
//**************************************
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
include_once('db.php');
$result = mysql_query("SELECT DISTINCT level1 FROM categories WHERE category='$drop_var'")
or die(mysql_error());
echo '<select name="drop_2" id="drop_2">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['level1'].'">'.$drop_2['level1'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_2').hide();
$('#drop_2').change(function(){
$('#wait_2').show();
$('#result_2').hide();
$.get(\"pla2.php\", {
func: \"drop_2\",
drop_var: $('#drop_2').val()
}, function(response){
$('#result_2').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
//**************************************
// Second selection results //
//**************************************
if($_GET['func'] == "drop_2" && isset($_GET['func'])) {
drop_2($_GET['drop_var']);
}
function drop_2($drop_var)
{
include_once('db.php');
$bresult = mysql_query("SELECT DISTINCT level2 FROM categories WHERE level1='$drop_var'")
or die(mysql_error());
echo '<select name="drop_3" id="drop_3">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_3 = mysql_fetch_array( $bresult ))
{
echo '<option value="'.$drop_3['level2'].'">'.$drop_3['level2'].'</option>';
}
echo '</select> ';
echo '<input type="submit" name="submit" value="Submit" />';
}
?>
答案 0 :(得分:2)
使用htmlentities?
.htmlenteties($drop_2['level2']).
答案 1 :(得分:0)
您可以将其替换为html特殊字符,替换为单引号字符。 请参阅list here:
答案 2 :(得分:0)
我明白了。我不得不改变
"SELECT DISTINCT level2 FROM categories WHERE level1='$drop_var'"
到
"SELECT DISTINCT level2 FROM categories WHERE level1='".mysql_real_escape_string$drop_var"'"