armlocker Posted November 15, 2012 Share Posted November 15, 2012 Hi there Error keeps popping up and I've tried everything to rectify. Its a pretty long error message that appears on the home page of Knowledge is Power, and starts like this: '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/html/index.php' on line 37: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given The error is occurring on line 37 - that I know. Any pointers in the right direction will be most appreciated. Link to comment Share on other sites More sharing options...
Antonio Conte Posted November 15, 2012 Share Posted November 15, 2012 This happens when an executed query returns an error. The way to solve this is to look at your query. Something is wrong with it. The error is really happening in mysqli_query(). Try echo out the query to look for obvious errors. The next step is running the query in something like phpmyadmin to make sure it works. You can compare the error to a PHP syntax error, only that Its happening in MySQL instead 2 Link to comment Share on other sites More sharing options...
armlocker Posted November 18, 2012 Author Share Posted November 18, 2012 Hi Antonio I've been trying to work through this methodically using the debugging techniques in Larry's other php book, but still really stuck with this script. The errors are echoed out at: http://wolfcut.co.uk/html/index.php I have narrowed it down to errors occuring in creation of the database on my hosting site - can you take a look an tell me what you think, much appreciated as always Link to comment Share on other sites More sharing options...
Antonio Conte Posted November 19, 2012 Share Posted November 19, 2012 Provide us some code. Hard to find errors without something to look at. Your queries seems syntactically ok from what I can see. Use var_dump() on the result of mysqli_query(). If it returns false, then you know there's a syntax error. Only tip I can give you right now. I'm pretty sure this is related to syntax errors. 1 Link to comment Share on other sites More sharing options...
Bill Posted November 19, 2012 Share Posted November 19, 2012 I think I had a similar problem but it was a long time ago. The query to most popular pages could be the source of the error. Try replacing this query with what you have in your code in index.php q = "SELECT COUNT(history.id) AS num, pages.id, pages.title FROM pages, history WHERE pages.id=history.page_id AND history.type='page' GROUP BY (history.page_id) ORDER BY num DESC LIMIT 10"; Cheers Link to comment Share on other sites More sharing options...
armlocker Posted November 19, 2012 Author Share Posted November 19, 2012 Nope that didn't work either.... error where code starts begins from here. I copied it straight off the book, and proof read it. I can't really see where I am going wrong. <?php echo '<h3>Most Popular Pages</h3><p>'; $q = "SELECT COUNT(history.id) AS num, pages.id, pages.title FROM pages, history WHERE pages.id=history.page_id AND history.type='page' GROUP BY (history.page_id) ORDER BY num DESC LIMIT 10"; $r = mysqli_query($dbc, $q); $n = 1; while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<h4>$n. <a href=\"page.php?id=$row[1]\">$row[2]</a></h4>\n"; $n++; } echo '</p>'; ?> <?php echo '<h3>Highest Rated Pages</h3><p>'; $q = "SELECT ROUND(AVG(rating),1) AS average, pages.id, pages.title FROM pages, page_ratings WHERE pages.id=page_ratings.page_id GROUP BY (page_ratings.page_id) ORDER BY average DESC LIMIT 10"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<h4>$row[0]. <a href=\"page.php?id=$row[1]\">$row[2]</a></h4>\n"; } echo '</p>'; ?> =================== On another note: where do I put this piece of code in to show errors: // show errors ini_set('display_errors', 1); // adjust error reporting: error_reporting(E_ALL | E _STRICT); ==================== Link to comment Share on other sites More sharing options...
Antonio Conte Posted November 19, 2012 Share Posted November 19, 2012 Then you are most likely not connected to the DB. I see no other explanation. (And don't see any connection code here) You should place those lines at the top of scripts. Link to comment Share on other sites More sharing options...
armlocker Posted November 19, 2012 Author Share Posted November 19, 2012 ..... begining of code goes like this: <?php require ('./includes/config.inc.php'); require (MYSQL); if ($_SERVER['REQUEST_METHOD'] == 'POST') { include ('./includes/login.inc.php'); } include ('./includes/header.html'); ?> <h3>Welcome</h3> <p>Welcome to Knowledge is Power, a site dedicated to keeping you up to date on the Web security and programming information you need to know. Blah, blah, blah. Yadda, yadda, yadda.</p> ========================== I've paid up for a hosting company 'Fatcow', so do I still need that open? I'm now going to double check the config.php script and see what I can find.... Thank you Antonio / Bill131 Link to comment Share on other sites More sharing options...
Larry Posted November 19, 2012 Share Posted November 19, 2012 Or, most likely, your database is not setup properly. 1 Link to comment Share on other sites More sharing options...
Recommended Posts