在 html 文本区域中输入引号和双引号,而数据库中的插入操作失败。可能吗?

Enter quotes and double quotes in a html textarea without an insertion operation fail in database. Is it possible?

在我的站点中,我有一个文本区域,其文本被插入到我的数据库中的一个字段中。 我希望能够在数据库中的插入操作失败的情况下输入引号和引号。可能吗?我该怎么办?

我有这个代码。

HTML

<div class="field">
    <label class="etichetta">Descrizione</label>
    <br>
    <textarea name="descrizione" rows="10" cols="40" maxlength="650"></textarea>
</div>

PHP

.
.
$descrizione = $_POST['descrizione'];

$query = "INSERT INTO couponFuturi (coupon, descrizione, immagine, alt, prezzoOriginale, prezzoScontato, scadenza, sezione)
VALUES ('$coupon', '$descrizione', '$imgUrl', '$imgAlt', '$prezzoOriginale', '$prezzoScontato', '$scadenza', '$sezione')";

$result = mysqli_query($db, $query);

插入操作returns由于引号和双引号的存在造成的语法错误。

使用php的addslashes()方法在保存到数据库时在引号前添加斜线,当您从数据库中获取数据并显示给用户时使用stripslashes()[=14] =]

// at the time of inserting the data in db
$descrizione = addslashes($_POST['descrizione']);

// when you get the data from db to display
$descrizione = stripslashes($descrizione);