0

I am trying to fetch TaxRate data from a table and I'm trying to select the first array only. However, I keep getting this error

"Fatal error: Uncaught Error: Call to a member function fetch_array() on boolean in C:\xampp\htdocs\flowerique\shoppingCart.php:77 Stack trace: #0 {main} thrown in C:\xampp\htdocs\flowerique\shoppingCart.php on line 77"

Does anyone know the cause of this error and how do I fix it? Thanks!

This is my code :

        //Retrieve Current GST Pricing 
        $qry = "SELECT * FROM gst GROUP BY EffectiveDate DESC";
        $stmt = $conn->prepare($qry);
        $stmt->execute();
        //$stmt->close();
        $result = $conn->query($qry);    
        $row = $result->fetch_array();       // This is line 77 
        while($row["EffectiveDate"] < date("Y-m-d"))
        {
            $row = $result->fetch_array();
        }
        $currentTaxRate = $row["TaxRate"];

Image of SQL Table

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • I have tried the SQL Query and can confirm that it works. – Poopin Mah Business Jan 28 '21 at 09:22
  • Change `SELECT * FROM gst GROUP BY EffectiveDate DESC` to `SELECT * FROM gst ORDER BY EffectiveDate DESC` and always check the result from the `$conn->query($qry)` call. – Zhorov Jan 28 '21 at 09:24
  • 2
    Why do you call `execute()` __and__ `query()`? – droopsnoot Jan 28 '21 at 09:28
  • 1
    Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) P.S. Droopsnoot is right, you are executing the query twice, for no apparent reason. If you aren't accepting user input into this query then there's no value in using prepared statements. – ADyson Jan 28 '21 at 09:43

0 Answers0