开发者

Why my php can't print out the string I input?

开发者 https://www.devze.com 2023-02-19 20:28 出处:网络
Here is the code I input... mysql_query(\"INSERT INTO test (string) VALUES (\'tes><ssst\')\"); And this is how I query the result out:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消