$alerter2="false";
for ($counter = 0; $counter <= count($filter); $counter++) {
$questionsubmitted=strtolower($_POST[question]);
$currentcheck =$filter[$counter];
$foundvalue=stripos((string)$questionsubmitted,(string)$currentcheck);
echo $foundvalue;
if ($foundvalue==0) {
$alerter2="true";
} else { }
}
if (!($alerter2=="true")) {
$sql="INSERT INTO Persons (Name, Email, Question)
VALUES
('$_POST[name]','$_POST[email]','$_POST[question]')";
} else {
echo "Please only post appropriate questions";
}
由於某些原因,每當我運行這個,每次迭代stripos都會返回0。它應該是一個過濾器,並使用回聲,我發現每當它出現時,stripos都是0。然而,當我在if中使用0時,即使那些沒有單詞的人也會返回true。奇怪的布爾反應
我應該在哪裏使用mysql_real_escape_string?查詢後?請注意,我將這段代碼放在了我希望將用戶輸入保存到數據庫的地方。
使用'mysql_escape_real_string();'您'$ sql'內'$ _POST'變量將是另一個事 – kjy112 2011-03-15 14:05:19
SQL注射攻擊! – Arafangion 2011-03-15 14:05:54
使用字符串表示「true」和「false」。真?? – Spudley 2011-03-15 14:08:51