我有這個PHP(測試):PHP回聲結果從MySQL SELECT
<?php
if (isset($_POST['submit'])) {
$link = mysqli_connect("localhost","php","","A");
$query = "SELECT passport FROM users WHERE mail = '$_POST[mail]';";
$result = $link->query($query);
}
?>
手動選擇使用相同$query
顯示:
mysql> SELECT passport FROM users WHERE mail = '[email protected]';
+----------------------+
| passport |
+----------------------+
| 8KQSWCZPJAUV1M9D4TFG |
+----------------------+
1 row in set (0.00 sec)
我想呼應$result
在PHP這應該顯示8KQSWCZPJAUV1M9D4TFG
,但它是空的。我在這裏做錯了什麼?
更新:
<?php
if (isset($_POST['submit'])) {
$link = mysqli_connect("localhost","php","","A");
$query = "SELECT passport FROM users WHERE mail = '$_POST[mail]';";
$result = mysqli_query($query);
$row = mysqli_fetch_assoc($result);
echo $row["passport"];
}
?>
這也仍然是零。
http://www.php.net/manual/en/mysqli-stmt.fetch.php – Alen
你可以刪除;從查詢字符串的末尾開始(如果需要),並在下一行回顯$ query,以確保準確生成了哪個查詢。 –