2016-04-27 123 views
0

我有兩個php值,分別是$ email和$ pass。簡單的SQL查詢從表中選擇電子郵件地址=電子郵件

電子郵件 - 行的MySQL數據庫 密碼名稱 - 行名稱在MYSQL數據庫

我運行一個SQL查詢,從表成員選取電子郵件= $電子郵件和密碼= $通行證。

我然後運行mysqli_query查看是否存在行,我沒有得到任何結果。回聲肯定會迴應信息匹配的ID。

//Get the connection info. 
global $connect; 

$sql = "SELECT FROM members WHERE email='$email' AND password='pass'"; 

//Fetch the row and store the ID of this row. 
$row = mysqli_query($connect, $sql); 
$id = $row['userID']; 

echo $id; 
+2

請使用PHP的[內置函數(http://jayblanchard.net/proper_password_hashing_with_PHP.html)來處理密碼的安全性。如果您使用的PHP版本低於5.5,則可以使用'password_hash()'[兼容包](https://github.com/ircmaxell/password_compat)。確保你[不要逃避密碼](http://stackoverflow.com/q/36628418/1011527)或在哈希之前使用其他任何清理機制。這樣做會改變密碼並導致不必要的附加編碼。 –

+1

[Little Bobby](http://bobby-tables.com/)說[你的腳本存在SQL注入攻擊風險。](http://stackoverflow.com/questions/60174/how-can-i-prevent -sql -injection-in-php)瞭解[MySQLi]的[prepared](http://en.wikipedia.org/wiki/Prepared_statement)語句(http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)。即使[轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –

+0

您的查詢未選擇任何內容。你有'SELECT FROM'。你需要選擇一些列,例如'SELECT * FROM' –

回答

2

除了這個代碼大量暴露給SQL注入的事實..你正在查詢數據,但沒有獲取結果。

添加取命令:

$data = mysqli_query($connect, $sql); 
$row = mysqli_fetch_assoc($data); 
$id = $row['userID']; 
相關問題