使用MySqli如何使用撇号正确安全地存储和检索字符串?

时间:2018-04-17 16:53:09

标签: php mysqli encoding utf-8

每当我向数据库提交表单时,它都会运行这一点:

<?php
include('connect.php');
$title =  mysqli_real_escape_string($link, $_POST['title']);
$subtitle = mysqli_real_escape_string($link, $_POST['subtitle']);
$etad =  mysqli_real_escape_string($link, $_POST['etad']);
$author =  mysqli_real_escape_string($link, $_POST['author']);
$Author_URL = mysqli_real_escape_string($link, $_POST['Author_URL']);
$URL =  mysqli_real_escape_string($link, $_POST['URL']);
$sql = "INSERT INTO posts (title, subtitle, etad, author, Author_URL, URL) VALUES ('" . $title . "', '" . $subtitle . "', '" . $etad . "', '" . $author . "', '" . $Author_URL . "', '" . $URL . "')";
if (!mysqli_query($link,$sql)) { die('Error: ' . mysqli_error($link)); }
header("Location: https://www.atheistunlimited.com/beta/index.php?post=success");
?>

但是,如果我存储尝试存储带有撇号的单词,它会变形。 (EX:Don't变成Don’t

我如何能够使用撇号安全地存储和检索字符串?

0 个答案:

没有答案