2012-05-27 65 views
0

它不打印結果。不知道爲什麼。一切都整齊地評論php已準備好聲明

我得到沒有錯誤顯示,沒有語法褻瀆,它只是不打印任何結果。但是,我知道值通過表單傳遞給這個處理php頁面,所以錯誤不在那裏。在數據庫中,我已經加密了除「公司」之外的所有字段 - 因此,我想通過嘗試獲取結果來查看這是否會起作用。

// 1. Creating a new server connection 

$db = new mysqli('localhost', 'root', '', 'developers'); 
if ($db->connect_errno) { 
    printf("Connect failed: %s\n", $mysqli->connect_error); 
    exit(); 
} 
// 2, Creating statement object 
$stmt = $db->stmt_init(); 

// 3, Creating a prepared statement 
if($stmt->prepare("SELECT company FROM accesoweb WHERE username = AES_DECRYPT(?, 'salt')")) { 

//4. Binding the variable to replace the ? 
    $stmt->bind_param('s', $username); 

    printf("Error: %d.\n", $stmt->errno); 


// 5. Executing query 
    $stmt->execute(); 


// 6. Binding the result columns to variables 
    $stmt->bind_result($company); 


// 7. Fetching the result of the query 
    while($stmt->fetch()) { 
     echo $company; 
    } 

// 8. Closing the statement object 
    $stmt->close(); 

// 9. Closing the connection 

$mysqli->close(); 

}

,我只是包含在MySQL中插入代碼爲:

INSERT INTO accesoweb (company, username,email,password) 
VALUES 
('hola', 
AES_ENCRYPT('maria','salt'), 
AES_ENCRYPT('sumail','salt'), 
AES_ENCRYPT('password',' salt') 


); 

因此,上述(該行實際上,該「公司」是什麼,我試圖恢復通過PHP代碼

+1

是PHP或配置爲輸出錯誤的Web服務器?嘗試帶有調試跟蹤的簡單腳本,逐步添加代碼以查看哪條線路失敗。 – Jake

+1

好吧,當我寫錯了,它抱怨,它一直在抱怨,它只是因爲'大概'我擦除了所有的錯誤而停止。其實我有這個:error_reporting(E_ALL | E_STRICT); ini_set('display_errors','On');在我的腳本頂部 – iaintunderstand

+0

如果我沒有記錯,'prepare'是MySQLi對象的一種方法,而不是MySQLiStatement對象。 –

回答

2
SELECT company FROM accesoweb WHERE username = AES_DECRYPT(?, 'salt') 

應該

SELECT company FROM accesoweb WHERE username = AES_ENCRYPT(?, 'salt') 

OR

SELECT company FROM accesoweb WHERE AES_DECRYPT(username, 'salt') = ? 
+0

賓果男人!現在是20:51。一直以來,從09:00開始編寫完整的代碼,因缺乏可靠的例子而在互聯網上瘋狂。這就是爲什麼一本書如此必要。我無法找到一份可靠的綜合教程,所以我無法學習,但通過試驗和錯誤和位在這裏和那裏。比你!! – iaintunderstand

+0

Dziękujębardzo(謝謝你波蘭語) – iaintunderstand

+0

這是一個可怕的邏輯錯誤發現! – Jake