当我在 PHP 中保存这个字符串时:
John: "Yes you can".
在我的数据库中保存为:
John: \
我怎样才能用“保存这些字符串(显然不删除”)。 这是我的 PHP 代码:
$titlepost= mysql_real_escape_string($_POST['title']);
$query = "INSERT INTO `titles` (`title`) VALUES ( '".$titlepost."')";
$res = mysql_query($query) or die("Failed".mysql_error() );
echo $titlepost;
output:
John: \\
表格:
$title = mysql_real_escape_string($_GET['title']);
<form method="post" action="title.php?done=yes" enctype="multipart/form-data">
<input type="text" size="25" name="title" <?php echo "value=\"".$title."\""; ?> >
<input id="starit" name="submit" value="titleit" type="submit" />
</form>
最佳答案
您的问题与 PHP 或 MysQL 无关。
它和非常简单的 HTML 语法规则一样愚蠢。 很明显,代码
<input value="John: "YES you can>
将只显示引用的“John:”部分。 为了使其正确,必须在值中编码特殊符号
$titlepost = htmlspecialchars($titlepost,ENT_QUOTES);
?>
<input type="text" name="title" value="<?=$titlepost?>">
至于斜线 - 这是愚蠢的过度引用问题。只引用你的字符串一次,并确保你关闭了 magic_quotes_gpc
关于php - 如何在 PHP 中保存这个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10311051/