Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
textarea Javascript中的撇号_Javascript_Html_Sql Server - Fatal编程技术网

textarea Javascript中的撇号

textarea Javascript中的撇号,javascript,html,sql-server,Javascript,Html,Sql Server,我创建了一个公司论坛。用户可以创建帖子来共享信息。为了做到这一点,目前,他们用一个基本的文本区完成了一个表单。我的问题是,当他们写一个带撇号的单词时,代码会将撇号解释为单引号,并创建一个异常。我将在下面向您展示代码和示例 Html: <!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8"> </head> &l

我创建了一个公司论坛。用户可以创建帖子来共享信息。为了做到这一点,目前,他们用一个基本的文本区完成了一个表单。我的问题是,当他们写一个带撇号的单词时,代码会将撇号解释为单引号,并创建一个异常。我将在下面向您展示代码和示例

Html:

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <div id="admin">
      <div v-if="seenNews" id="news">
        <div class="form">
          <h4>Create a post</h4>
          <form class="newPost" action="/newPost" method="POST">
            <label id="titleLabel" for="titleInput">Title : </label>
            <input type="text" id="titleInput" name="titleInput" required>
            <label id="contentLabel" for="contentInput">Content : </label>
            <textarea id="contentInput" name="contentInput" cols="40" rows="5" required></textarea>
            <button type="submit">Create</button>
          </form>
        </div>
      </div>
    </div>
  </body>
</html>

DAO.js

const sql = require('mssql');

class DAO {
    constructor() {
        this.sqlConfig = {
            user: 'username',
            password: 'password',
            server: 'SERVER',
            port:port,
            database: 'DB',
            options: {
                enableArithAbort: false,
                encrypt:false
            }
        }
    }

    async newPost(title, content) {
        try {
            let req = 'INSERT INTO DB.dbo.[Table] (title, content) VALUES (\''+title+'\',\''+content+'\')';
            console.log(req);
            await sql.query(req).then(value => {
                return true;
            });
        } catch (e) {
            console.log(e);
            return false;
        }
    }
}
例如,如果用户创建一个包含以下内容的帖子:
Smith女士的钥匙在前台
,我会将其放在控制台中:

RequestError: Unclosed quotation mark after the character string ')'.

也许如果我创建一个函数来查找对字符进行en编码的字符,它就可以修复它,但我不知道怎么做。

我最终使用JS函数replace()将字符串中的简单引号替换为两个简单引号<代码>'相当于sql server中的js
\'


“插入PROFACE.dbo.[Posts](title,content)值(\''+title.replace(/'/gi,'')+'\',\''+content.replace(/'/gi,'')+'\'))”

,欢迎您介绍sql注入攻击。正如@epascarello指出的,您应该防止注入安全问题:。有人可以下载/删除你的整个数据库…我会处理的,谢谢。
RequestError: Unclosed quotation mark after the character string ')'.