作者fatfattim (fattim)
看板PHP
标题Re: [请益] 关於使用者输入 格式问题
时间Sat Aug 9 21:03:42 2008
※ 引述《ybite (小犬)》之铭言:
※ 引述《fatfattim (fattim)》之铭言:
/* 以下是为了避免SQL injection */
$id = mysql_real_escape_string($id);
$name = mysql_real_escape_string($name);
$Compiler = intval($Compiler);
$Algorithm = intval($Algorithm);
$comment = mysql_real_escape_string($comment);
$sql="INSERT INTO OrderBook (学号,姓名,Compiler,Algorithm,comment) VALUES
('$id','$name', $Compiler, $Algorithm, '$comment')";
恩,我去看了PHP.net 大概知道 mysql_real_escape_string的用法了
应该主要是用来跳脱特殊字元,
但,如果我今天允许并想存成
$name='';
$id=\\;
用了跳脱字原的函式後,我去phpmyadmin 查询,发现资料为
\'\' 以及 \\\\
这样好像就不能存成我真正需要的资料?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.168.143.29
1F:推 ybite :这就奇怪了,我测的话没有问题啊 08/10 02:23
2F:→ ybite :可以把你的SQL式子echo出来吗? 08/10 02:23
3F:→ fatfattim :我寄给你好噜 code 太占版面~~ ^^ 08/10 14:43