This question already has an answer here:
I load data from mysql database and display it into listview jqm. Here is my code:
<?php
include "connect.php";
$result = mysqli_query($con,"SELECT * FROM story");
id==$row['id'];
echo "<ul data-role='listview' data-inline='true'>";
while($row = mysqli_fetch_array($result)) {
echo "<li>" ;
echo "<a href='view.php?id=".$rows['id']."' data-rel='external'>";
echo $row['name'];
echo "</a>";
echo "</li>";
}
echo "</ul>";
?>
and view page :
<?php
include "connect.php";
$id = $_GET['id'];
$result = mysqli_query($con,"SELECT * FROM story WHERE id='".$id."'");
$row = mysqli_fetch_array($result);
echo $row['content'];
?>
But it not working and this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\1\view.php on line 11. What should I do ?
</div>
This error shows that the SQL Query is unable to get data into $result and if you try to print this result on the screen it will show you bool(false) as output. This parameter when passed into the mysqli_fetch_array() does not fetch array for you because it requires a TRUE boolean value.
First try to get the data from the database into the $result, print it and then proceed forward.
Maybe this will help,
$result = mysqli_query($con,"SELECT * FROM story WHERE id='.$id.' ");
Remember to always use error checking methods like die, mysqli_error, mysqli_connect_error(), mysqli_connect_errno() etc for better debugging.
You don't check for any errors. You just assumed everything worked fine.
Instead of:
$result = mysqli_query($con,"SELECT * FROM story WHERE id='".$id."'");
use:
$result = mysqli_query($con,"SELECT * FROM story WHERE id='".$id."'") or die(mysqli_error($con));
In your connect.php
file use:
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
And don't forget to escape the values from global variables.