PHP 将 \ 插入 sql table
PHP inserting \ into sql table
我正在使用 html 表单文本输入和 CKEditor 来允许客户端将帖子插入博客数据库。图片输入采用 html img 标签,例如,如果您选择插入图片,CKEditor 也会发送 img 标签。
我的问题是 PHP 正在为 img 标签中的引号插入反斜杠,我只是不确定如何防止这种情况。我查看了文档,但不想做任何会造成伤害的事情。有什么建议么?自从我使用 PHP 和 SQL.
以来已经有一段时间了
// set parameters and execute
$title = $_POST['postBlogTitle'];
$content = $_POST['editor1'];
$image = $_POST['postBlogImage'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and bind
$stmt = $conn->prepare("INSERT INTO Blog (TITLE, CONTENT, IMAGE) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $title, $content, $image);
为了帮助那些将来可能会看到这个的人:
测试magic_quotes_gpc是否开启:
将下面的代码粘贴到 php 文件中,然后将文件上传到您的网站,与您的 index.html 位于同一文件夹中。访问 url (www.myWebsite.com/phpinfo.php)
<?php phpinfo() ?>
向下滚动,您最终会在状态中找到它。正如@Barmar 所说,如果打开,请使用 stripslashes()。
尝试使用 stripslashes .
$image = stripslashes($_POST['postBlogImage']);
我正在使用 html 表单文本输入和 CKEditor 来允许客户端将帖子插入博客数据库。图片输入采用 html img 标签,例如,如果您选择插入图片,CKEditor 也会发送 img 标签。
我的问题是 PHP 正在为 img 标签中的引号插入反斜杠,我只是不确定如何防止这种情况。我查看了文档,但不想做任何会造成伤害的事情。有什么建议么?自从我使用 PHP 和 SQL.
以来已经有一段时间了// set parameters and execute
$title = $_POST['postBlogTitle'];
$content = $_POST['editor1'];
$image = $_POST['postBlogImage'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and bind
$stmt = $conn->prepare("INSERT INTO Blog (TITLE, CONTENT, IMAGE) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $title, $content, $image);
为了帮助那些将来可能会看到这个的人:
测试magic_quotes_gpc是否开启:
将下面的代码粘贴到 php 文件中,然后将文件上传到您的网站,与您的 index.html 位于同一文件夹中。访问 url (www.myWebsite.com/phpinfo.php)
<?php phpinfo() ?>
向下滚动,您最终会在状态中找到它。正如@Barmar 所说,如果打开,请使用 stripslashes()。
尝试使用 stripslashes .
$image = stripslashes($_POST['postBlogImage']);