Nikhilesh Posted July 2, 2019 Share Posted July 2, 2019 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/myritebook/public_html/footer.php on line 13 I am trying to fix the above error. Please Help. code is given below: <?php include 'db.php'; if ($conn) { echo "Database Found "; } else { die("Database connection failed"); } $find_count=mysqli_query($conn,"SELECT * FROM count_number"); while($row=mysqli_fetch_array($find_count)); { $current_count=$row['count']; $new_count=$current_count+1; try{ $sql= "UPDATE count_number SET count = '$new_count' where id=1"; $update_count=mysqli_query ($conn,$sql); } catch(Exception $e){ echo 'error;'.$e->getMessage(); } } ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted July 2, 2019 Share Posted July 2, 2019 Then the chances are that your query failed and returned "false". See what mysqli_error() tells you. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 2, 2019 Share Posted July 2, 2019 (edited) Which line of code is the bad one? That helps PS - My php manual does not show this function in use - mysqli_fetch_array Edited July 2, 2019 by ginerjm Quote Link to comment Share on other sites More sharing options...
Barand Posted July 2, 2019 Share Posted July 2, 2019 Given the error message, my money's on the line that contains "mysqli_fetch_array()" Quote Link to comment Share on other sites More sharing options...
Barand Posted July 2, 2019 Share Posted July 2, 2019 53 minutes ago, ginerjm said: PS - My php manual does not show this function in use - mysqli_fetch_array https://www.php.net/manual/en/mysqli-result.fetch-array.php Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 2, 2019 Share Posted July 2, 2019 That's great but as I said my manual does not show it as an available function. Do a Search and you only get mysqli_fetch Quote Link to comment Share on other sites More sharing options...
Barand Posted July 2, 2019 Share Posted July 2, 2019 Yet, there it is in the manual. The php.net function search is crap in this respect. You have to search first for the "mysqli-result" class to get to the methods fetch() is mysqli-statement method fetch_assoc() is a mysqli-result method. That's the main problem with mysqli - there are two different sets of methods to process the results depending on whether you used query() or prepare(). Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 2, 2019 Share Posted July 2, 2019 (edited) 47 minutes ago, Barand said: The php.net function search is crap in this respect. You have to search first for the "mysqli-result" class to get to the methods Alternatively, you could use a search engine like Google. Searching for function names like "mysqli_fetch_array" usually lead to the corresponding PHP manual page, without needed to know the overarching class. For function names that are common to multiple programming languages, you could try "php count". More often than not, the PHP manual is in the first few links...at least it has been for me. Minor side note @Nikhilesh: mysqli_fetch_array() gives you both an associative array and a numeric array for your data. In other words, if your database table has 2 columns (id and count), $row will contain 4 values ($row[0] - containing the ID, $row[1] - containing count, $row['id'], and $row['count']). I'm guessing that most people who use mysqli_fetch_array() never use the numeric indexes. If you don't plan on using the numeric indexes, you would be better off using mysqli_fetch_assoc() instead. This type of advice also goes for the "*" in your query. Unless you need every column from your database table, it's better to specify the columns you actually need. Edited July 2, 2019 by cyberRobot fixed typo / minor edits Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.