I have created a simple PHP page which retrieves data from a POST request and saves it in MYSQL database. The data is getting inserted in the proper way. Now, I want to execute a Select query to retrieve the data from the table and show it in a UI Table. The problem is that the Select statement is giving an error.
This is the error:
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
This is the PHP code:
<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>
Where am I going wrong? What can be done to get the desired output?