Page 1 of 1

Need Help with a PHP/MYSQL error I am getting.

Posted: Mon Feb 02, 2009 9:59 am
by gilal
Hi Guys,

I am following Head First PHP and MYSQL by Oreily and I got stuck with an error which I can not figure out how to fix it. I double checked all the syntax and still nothing. If anyone can help, ill really appreciate it.

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/giladal/public_html/guitarwars/admin.php on line 21

Here is the link: http://www.giladwebdesign.com/guitarwars/admin.php

If anyone can help me, I will greatly appreciate it.



And this is the code:

Code: Select all

<!doctype html public "-//W3C//DTD HTML 4.0 //EN"> 
<html>
<head>
       <title>Guitar Wars - Admin</title>
</head>
<body>
<?php
require_once('includes/constants.php');
 
 
//Connect to the database
 
$dbc= mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
 
//retrieve the score data from the MySQL
$query = "SELECT * FROM guitarwars ORDER BY score DESC, date, ASC";
$data = mysqli_query($dbc, $query);
 
 
//Loop through the array of score data, formatting it as HTML
echo'<table>';
while($row= mysqli_fetch_array($data)) {
    //Display the score data
    echo '<tr class="scorerow"><td><strong>' . $row['name'] . '</strong></td>';
    echo '<td>' . $row['date'] . '</td>';
    echo '<td>' . $row['score'] . '</td>';
    echo '<td><a href="removescore.php?id=' . $row['id'] . '$amp;date=' . $row['date'] .
    '&name=' . $row['name'] . '$amp;sore=' . $row['score'] . '&screenshot=' .
    $row['screenshot'] . '">Remove</a></td></tr>';
}
 
echo '</table>';
 
mysqli_close($dbc);
?>
 
</body>
</html>
 

Re: Need Help with a PHP/MYSQL error I am getting.

Posted: Mon Feb 02, 2009 10:05 am
by mickeyunderscore
You have a syntax error in your database query:

Code: Select all

SELECT * FROM guitarwars ORDER BY score DESC, date, ASC
Should be:

Code: Select all

SELECT * FROM guitarwars ORDER BY score DESC, date ASC
This parameter error showed up because the function mysqli_query() was returning a boolean false, due to the query not executing properly.

Re: Need Help with a PHP/MYSQL error I am getting.

Posted: Mon Feb 02, 2009 10:18 am
by gilal
mickeyunderscore wrote:You have a syntax error in your database query:

Code: Select all

SELECT * FROM guitarwars ORDER BY score DESC, date, ASC
Should be:

Code: Select all

SELECT * FROM guitarwars ORDER BY score DESC, date ASC
This parameter error showed up because the function mysqli_query() was returning a boolean false, due to the query not executing properly.
Ok.... that seemed to work... I remember fixing that issue before and it didnt work, but now its working..

Thanks! :)