0

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

MyRadio'],ENT_QUOTES) 。“'”。htmlspecialchars($_REQUEST['section'],ENT_QUOTES) 。“'”。htmlspecialchars($_REQUEST['chapter'],ENT_QUOTES) 。
")";

谢谢你 ...

4

5 回答 5

0

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

$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')";
于 2013-08-24T06:57:30.883 回答
0

你可以像这样使用它

insert into $user(id,question,option1,option2,option3,option4,correctAnswer,category,section,chapter)
values
(
"'.$newstd.'",
'".htmlspecialchars([\'$question1\'],ENT_QUOTES)."'
)
于 2013-08-24T06:48:56.333 回答
0
"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) .
")";
于 2013-08-24T06:51:33.663 回答
0

您的查询应该像

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

你有问题double quotes

于 2013-08-24T06:51:39.820 回答
0

正确的代码是

"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) . "')";
于 2013-08-24T06:52:04.027 回答