我創建了一個簡單的PHP頁面,它從POST請求中檢索數據並將其保存在MYSQL數據庫中。數據以正確的方式插入。現在,我想執行Select查詢來從表中檢索數據並將其顯示在UI表中。 問題是Select語句給出了一個錯誤。MySql Select查詢返回錯誤結果
這是錯誤:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\abhideep_test_project\welcome.php on line 48
這是PHP代碼:
<html>
<body>
<?php $name = $_POST["name"];
$email = $_POST["email"];
$mobile = $_POST["mobile"];
$address = $_POST["address"];
//=============Data Insertion=================
// Create connection
$con=mysqli_connect("localhost","root","","employee_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
/*mysqli_query($con,"INSERT INTO employee_details (employee_name, employee_email, employee_mobile, employee_address)
VALUES ('Glenn', '[email protected]','9830098300','2/A, Work Lane')");*/
mysqli_query($con,"INSERT INTO employee_details (employee_name, employee_email, employee_mobile, employee_address)
VALUES ('$name','$email','$mobile','$address')");
mysqli_close($con);
//=============Data Insertion=================
//=============Data Display=================
$con=mysqli_connect("localhost","root","","employee_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT 'employee_id' , 'employee_name' , 'employee_email' , 'employee_mobile' , 'employee_address'
FROM 'employee_details' ");
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Address</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['employee_name'] . "</td>";
echo "<td>" . $row['employee_email'] . "</td>";
echo "<td>" . $row['employee_mobile'] . "</td>";
echo "<td>" . $row['employee_address'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
//=============Data Display=================
?>
</body>
</html>
我要去哪裏錯了?可以做些什麼來獲得理想的輸出?
列周圍是不是無效的,它只是返回的值。桌子周圍是。 –
@BartFriederichs,是的,謝謝你抓到這句話。更新答案刪除不正確的語句 – vee