我在下面的代码中有一个问题我怎么能管理sql字符串,因为它无法检索字符串中的问题问题我怎么能纠正字符串
<?php
$chapter = $_SESSION['chapters'] ;
if(isset($chapter))
{
$nchapter = count($chapter );
echo("You selected $nchapter chapters:<br> ");
for($i=0; $i < $nchapter; $i++)
{
($chapter[$i] . " ,");
echo $var1 = $chapter[$i] . " <br>";
$_SESSION['var1'] = $var1;
$db = mysql_connect("127.0.0.1","root","");
$db_select = mysql_select_db("db",$db);
echo $var1 ;
echo $sql = "select * from ".$_SESSION['tcsub']." where chapter='$var1'";
$query = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($query))
{
echo $data= htmlspecialchars_decode($row['question'], ENT_QUOTES);
}
}
}
?>
答案 0 :(得分:1)
$sql = "select * from ".$_SESSION['tcsub']." where chapter='".$var1."'";
echo $sql
试试这个,并告诉我们echo返回的内容。可能你的$ _SESSION不知道合适的桌子吗?