Php 面对fckeditor中的单引号问题

Php 面对fckeditor中的单引号问题,php,Php,我想通过fckeditor在数据库中输入单引号。但我的代码不适合我 “插入到$user中 (id、问题、选项1、选项2、选项3、选项4、正确答案、类别、章节) 价值观 (" .“,$newstd,”。 “,”.htmlspecialchars($_POST['FCKeditor0',ENT_引号)。 “,”.htmlspecialchars($_POST['FCKeditor1',ENT_引号)。 “,”.htmlspecialchars($_POST['FCKeditor2',ENT_引号)。

我想通过fckeditor在数据库中输入单引号。但我的代码不适合我

“插入到$user中 (id、问题、选项1、选项2、选项3、选项4、正确答案、类别、章节) 价值观 (" .“,$newstd,”。 “,”.htmlspecialchars($_POST['FCKeditor0',ENT_引号)。 “,”.htmlspecialchars($_POST['FCKeditor1',ENT_引号)。 “,”.htmlspecialchars($_POST['FCKeditor2',ENT_引号)。 “,”.htmlspecialchars($_POST['FCKeditor3',ENT_引号)。 “,”.htmlspecialchars($_POST['FCKeditor4',ENT_引号)。 “,”.htmlspecialchars($_请求['correctans],ENT_引号)。 “,”.htmlspecialchars($_请求['MyRadio'],ENT_引号)。 “,”.htmlspecialchars($_请求['section],ENT_引号)。 “,”.htmlspecialchars($_请求['chapter'],ENT_引号)。
")";


谢谢你…

你可以这样使用它

insert into $user(id,question,option1,option2,option3,option4,correctAnswer,category,section,chapter)
values
(
"'.$newstd.'",
'".htmlspecialchars([\'$question1\'],ENT_QUOTES)."'
)

您的查询应该是

"insert into $user(id,question,option1,option2,option3,option4,correctAnswer,category,section,chapter)
            VALUES
            (
            '".$newstd."' ,
            '" . htmlspecialchars($question1,ENT_QUOTES) ."'
            )";
您对双引号有问题

正确的代码是

"insert into $user (id,question,option1,option2,option3,option4,correctAnswer,category,section,chapter) VALUES ('$newstd','" . htmlspecialchars($question1, ENT_QUOTES) . "','" . htmlspecialchars($question2, ENT_QUOTES) . "','" . htmlspecialchars($question3, ENT_QUOTES) . "','" . htmlspecialchars($question4, ENT_QUOTES) . "','" . htmlspecialchars($_REQUEST['correctans'], ENT_QUOTES) . "'," . htmlspecialchars($_REQUEST['MyRadio'], ENT_QUOTES) . "'," . htmlspecialchars($_REQUEST['section'], ENT_QUOTES) . "','" . htmlspecialchars($_REQUEST['chapter'], ENT_QUOTES) . "')";

为了保持代码的可读性,您可以这样使用它

$question1= htmlspecialchars(['$question1'],ENT_QUOTES);
$question2= htmlspecialchars(['$question2'],ENT_QUOTES);
$question3= htmlspecialchars(['$question3'],ENT_QUOTES);
$question4= htmlspecialchars(['$question4'],ENT_QUOTES);
$correctans= htmlspecialchars($_REQUEST['correctans'],ENT_QUOTES);
$MyRadio= htmlspecialchars([$_REQUEST['MyRadio'],ENT_QUOTES);
$section= htmlspecialchars($_REQUEST['section'],ENT_QUOTES);
$chapter= htmlspecialchars($_REQUEST['chapter'],ENT_QUOTES);

"insert into $user (id,question,option1,option2,option3,option4,correctAnswer,category,section,chapter) VALUES (' ','$newstd','$quertion1','$quertion2','$quertion3','$quertion4','$correctans','$MyRadio','$section','$chapter')";
$question1= htmlspecialchars(['$question1'],ENT_QUOTES);
$question2= htmlspecialchars(['$question2'],ENT_QUOTES);
$question3= htmlspecialchars(['$question3'],ENT_QUOTES);
$question4= htmlspecialchars(['$question4'],ENT_QUOTES);
$correctans= htmlspecialchars($_REQUEST['correctans'],ENT_QUOTES);
$MyRadio= htmlspecialchars([$_REQUEST['MyRadio'],ENT_QUOTES);
$section= htmlspecialchars($_REQUEST['section'],ENT_QUOTES);
$chapter= htmlspecialchars($_REQUEST['chapter'],ENT_QUOTES);

"insert into $user (id,question,option1,option2,option3,option4,correctAnswer,category,section,chapter) VALUES (' ','$newstd','$quertion1','$quertion2','$quertion3','$quertion4','$correctans','$MyRadio','$section','$chapter')";