基本上,我試圖使用一個類,我發現讓從數據庫中的用戶數據,它的解析如下圖所示,從下面的功能的陣列中的所有數據:PHP陣列無法訪問
public function Get($field = NULL) {
if ($field == NULL)
{
$data = array();
while ($row = mysql_fetch_array($this->last_query))
{
$data[] = $row;
}
}
else
{
$row = mysql_fetch_array($this->last_query);
$data = $row[$field];
}
return $data;
}
這裏的PHP代碼我使用來獲取調用這個函數
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if($_SESSION['csrfToken'] == $_POST['csrfToken']) {
$email = $_POST['email'];
$password = $Security->Salt($Security->secParam($_POST['password']));
$DB->Query("SELECT * FROM `table` WHERE `email` = '$email' AND `password` = '$password'");
if($DB->num_rows() > 0) {
$results = $DB->Get();
} else {
echo "Account not found";
}
}
}
如果我做了對的var_dump $結果則顯示以下
array(1) {
[0]=> array(8) {
[0]=> string(1) "1" ["id"]=> string(1) "1"
[1]=> string(35) "[email protected]" ["email"]=> string(35) "[email protected]"
[2]=> string(32) "4f14dfef1efe0de64e2b176eac6051cd" ["password"]=> string(32) "4f14dfef1efe0de64e2b176eac6051cd"
[3]=> string(1) "1" ["status"]=> string(1) "1"
}
}
我怎樣才能訪問這些數據?我試着用以下方法調用它:
$email = $results['email'];
echo $email;
但它沒有顯示任何東西?
您的腳本可能容易受到[SQL注入](http://en.wikipedia.org/wiki/SQL_injection)的影響。 – Gumbo 2013-02-24 16:38:51