作者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
推 ybite :這就奇怪了,我測的話沒有問題啊 08/10 02:23
→ ybite :可以把你的SQL式子echo出來嗎? 08/10 02:23
→ fatfattim :我寄給你好嚕 code 太佔版面~~ ^^ 08/10 14:43