我在我的註冊頁面有這一行。PHP mysql結果問題
if (device_id_exists($_POST['device_id']) == true) {
$errors[] = 'Sorry the Serial Number \'' . htmlentities($_POST['device_id']) . '\' does not exist.';
}
我在我的功能頁面有這個。
function device_id_exists($device_id) {
$device_id = sanitize($device_id);
$query = mysql_query("SELECT COUNT(`numbers`) FROM `devicenumbers` WHERE `numbers` = '$numbers'");
return (mysql_result($query, 0) == 0) ? true : false;
如果我運行此查詢SELECT COUNT(
數字) FROM
devicenumbers WHERE
號= '1234567890'
(有效數字),則返回1 =找到匹配吧?如果我輸入一個假編號,它將返回一個「0」。 發生了什麼事情時,有一個有效的號碼,它仍然返回錯誤號碼不存在。如果我將結果更改爲== 1,它會提交任何數字?即時通訊DB新手呼籲任何幫助表示讚賞。我希望我提供了足夠的信息。
in device_id_exists()$數字來自哪裏?它應該是$ device_id? – Waygood 2013-03-25 17:29:00
無關:'return(mysql_result($ query,0)== 0)? true:false;'可以簡化爲'return(mysql_result($ query,0)== 0);' – scones 2013-03-25 17:30:07
IRRELEVANT:read [this](http://stackoverflow.com/questions/129677/whats-the-best - 方法 - 消毒 - 用戶輸入與php)關於衛生。 – cygorx 2013-03-25 17:34:29