我在以下代码中遇到问题如何管理 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);
}
}
}
?>