Echo data from database using PHP no errors but data will not show
Get the solution ↓↓↓I am currently working on a page for a local football team. I want to be able to insert the player information into a my database and then echo the data back onto the page for each player. I have created this code however there is no sign of any of my HTML coding being echoed back to me on the page. If anyone could help with this it'd be greatly appreciated.
<?php
$query = mysql_query("SELECT * FROM tbl_u14team");
while($rows = mysql_fetch_array($query)):
$name = $rows['name'];
$position = $rows['position'];
$age = $rows['age'];
$height = $rows['height'];
$biography = $rows['biography'];
$image = $rows['image'];
echo '<div id="teammember">
<img src="'.$image.'" />
p>Name:'.$name.'</br>
Position:'.$position.'</br>
Age:'.$age.'</br>
Height:'.$height.'</br>
Biography:'.$biography.'</p>
</div>';
endwhile;
?>
Answer
Solution:
[04-Sep-2014 04:50:54 America/Denver] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home2/localbu6/public_html/dafcyouth/u14s.php on line 14
This means your query has failed.
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
Since the error is complaining about aboolean
, (andFALSE
being a boolean and only returned if the query failed) - your query has failed.
Replace yourmysql_query
line with the following and take the necessary actions
$query = mysql_query("SELECT * FROM tbl_u14team") or die(mysql_error());
- Does your MySQL user have
SELECT
privileges on the database you're connected to?- And
SELECT
privileges on the table?
- And
- Does the table
tbl_u14team
exist? - Has your MySQL connection been disconnected before this code hits?
Answer
Solution:
Try puttingvar_Dump(mysql_fetch_array($query));
before thewhile
to see it the content array is as expected. Or do avar_Dump($rows)
within the while.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mark bundle as not supporting multiuse
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.