我想通过 fckeditor 在数据库中输入单引号。但是我的代码不适合我。
MyRadio'],ENT_QUOTES) 。“'”。htmlspecialchars($_REQUEST['section'],ENT_QUOTES) 。“'”。htmlspecialchars($_REQUEST['chapter'],ENT_QUOTES) 。
")";
谢谢你 ...
我想通过 fckeditor 在数据库中输入单引号。但是我的代码不适合我。
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')";
你可以像这样使用它
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) .
")";
您的查询应该像
"insert into $user(id,question,option1,option2,option3,option4,correctAnswer,category,section,chapter)
VALUES
(
'".$newstd."' ,
'" . htmlspecialchars($question1,ENT_QUOTES) ."'
)";
你有问题double 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) . "')";