0

我目前有这个将数据插入 SQL 服务器的查询。但由于问题可能包含包含单引号的特殊字符,因此它会跳过我的查询并且没有插入到数据库中。知道将单引号数据插入 SQL Server 数据库对我有用吗?示例:培训师的表现。

这是我将数据插入数据库的代码:

$sql_array = array();
    foreach ($_POST['question'] as $row => $name) {

        $question = $name;
        $qnsNo = $_POST['qnsNo'][$row];
        $input = $_POST['input'][$row];
        $options = $_POST['options'][$row];
        $others = $_POST['others'][$row];
        $compulsory = isset($_POST['compulsory'][$row]) ? $_POST['compulsory'][$row] : "";

        $idQuery = "SELECT max(surveyID) FROM scSurveyForm WHERE createBy = '$createBy' AND writeUp = '$writeUp'";
        $idResult = sqlsrv_query($conn, $idQuery);
        $rows = sqlsrv_fetch_array($idResult);
        $lastID = $rows[0];

        $sql_array[] = "('" . $question . "'," . $lastID . ",'" . $qnsNo . "','" . $input . "','" . $options . "','" . $others . "','" . $compulsory . "')";

        if (!empty($question)) {

            $query_single = "INSERT INTO scFormLayout(question, surveyID, qnsNo, input, options, others, compulsory)
  VALUES" . implode(', ', $sql_array);
            //echo $query_single.'<br/>';
            $status = sqlsrv_query($conn, $query_single);
            $sql_array = array();
4

0 回答 0