来自mySQL的PHP结果没有';t在输入值内显示引号


PHP result from mySQL doesn't show quotes inside input value

我正在使用"mysql_real_sescape_string"将数据插入mysql。

为了检索它,我使用条带斜线来回显它,它工作得很好,除了像本例中那样将值放在输入值中时。单引号很好用,例如:银河之家。。。但是双引号,剪切脚本,在第一个引号中:。示例:银河系的"主页"应该只有:银河系

如果我去掉条纹斜杠,它会显示:乳白色/

所以,仍然在第一句话中删去它。

这是脚本:

$id=mysql_real_escape_string($_POST[id]);
<?
echo stripslashes($Titlez['titlez']);
?>
<input type="text" size="150px" name="titlez" value="<? echo stripslashes($Titlez['titlez']); ?>">

我也尝试了这两个选项,但给出了相同的结果:

<?
$titlez = stripslashes($Titlez['titlez']);
echo '<input type="text" size="150px" name="titlez" value="'.$titlez.'">';
echo "<input type='"text'" size='"150px'" name='"titlez'" value='"".$titlez."'">";
?>

试试这个

$titlez = htmlentities(stripslashes($Titlez['titlez']));

当您将数据设置为必须使用htmlentities()的输入时,它会注意双引号。

http://php.net/htmlentities

除了在mysql中插入数据外,不应该使用mysql_real_eescape_string。此外,一旦数据存储在数据库中,mysql_real_eescape_string添加的斜杠(或用于转义特殊字符的任何字符)就会被删除,因此当您从数据库中提取数据时,不需要使用"stripeshases"或任何其他非转义方法。

正如其他人已经提到的,如果你还没有在php.ini中禁用Magic Quotes,你会想要禁用它。否则,额外的斜杠将自动添加到任何请求数据中。

一旦您将数据嵌入到HTML中,您将使用htmlentities(如Rezigned所述)来正确地转义特殊字符。