Why my php can't print out the string I input?
Here is the code I input...
mysql_query("INSERT INTO test (string) VALUES ('tes><ssst')");
And this is how I query the result out:
$result = mysql_query("SELECT * FROM test");
while($row = mysql_fetch_array($result))
{
echo $row['id'] . " ----开发者_JAVA技巧 " . $row['string'];
echo "<br />";
}
but I only get this result:
3 ---- tes>
I miss the missing part: "<ssst
", but when I go to the db, I can retrieve the string I inserted. What's happen? Thank you.
That's because your browser thinks <ssst
is an html tag. You should encode your output
while($row = mysql_fetch_array($result)) {
echo $row['id'] . " ---- " . htmlspecialchars($row['string']);
echo "<br />";
}
use htmlspecialchars to encode output
精彩评论