I earlier made a database in mysql and now i am trying to list all the values from it in a table, but I get the following error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean
on line: while ($row=mysql_fetch_array($result))
Here is my code:
$con=mysql_connect("localhost","root","");
if (!$con) {
die("Error: " . mysql_error);
}
mysql_select_db("my_db",$con);
$result = mysql_query("SELECT * FROM Users");
echo "<table border='1'>
<tr>
<th>Username</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Email adress</th>
</tr>";
while($row=mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['emailadress'] . "</td>";
echo"</tr>";
}
echo "</table>";
mysql_close($con);
I read other similar question but diden't get an answer.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…