0

I have this code:

$stmt8 = $conn->prepare("UPDATE centralizator_alerte 
                SET nr_alerte_nevalidate= nr_alerte_nevalidate-1,
                    nr_alerte_confirmate= nr_alerte_confirmate+1, 
                    timp_total_raportare_catalogare = timp_total_raportare_catalogare+?,
                    timp_mediu_raportare_catalogare=timp_total_raportare_catalogare/(nr_alerte_confirmate+nr_alerte_incorect_raportate+nr_alerte_gresit_raportate) 
                WHERE id_problema = ?");
$stmt8->bind_param("ss", $timp_raportare_catalogare, $id_problema);
$stmt8->execute();

Checking the error_log shows me that

[14-May-2020 14:23:58 Europe/Bucharest] PHP Fatal error: Call to a member function bind_param() on boolean in .... on line 162

Line 162 it's the bind_param that I added above. Having this error made me believe that the prepare returned false, so I copy-pasted the entire query in my SQL database and ran it, using values instead of ?, and it worked, the update updated my table. So, the next step was about the variables that I use in bind_param, so I checked them right before the $stmt and echo-ing them showed me that the values are alright indeed. I ran out of things to check, so I would like to ask if someone sees anything else?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Costin
  • 194
  • 1
  • 2
  • 16
  • have you a) put the variables themselves in the SELECT statement (in the app, not SQL database), and b) put the variables in the SELECT statement in place of the ?. – fraggley May 14 '20 at 11:40
  • i have tried both ways, if I the variables direct in the `SELECT` statement it's gives me the same error, but for `execut()` – Costin May 14 '20 at 11:46
  • You could simply check the content of `$stmt8` if you dont believe the error. do a `var_dump($stmt8)` and see what comes out – RiggsFolly May 14 '20 at 11:46
  • it is false, but I cannot see why it would be. – Costin May 14 '20 at 11:47
  • Changing every value with a given one, it works in my `phpmyadmin` `sql` interface, but the `vardump` still outputs `false` – Costin May 14 '20 at 11:56
  • 2
    To get errors out of PHP even in a LIVE environment add these 4 lines to the top of any `MYSQLI_` based script you want to debug `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);`. This will force any `MYSQLI_` errors to generate an Exception that you can see on the browser as well as normal PHP errors. – RiggsFolly May 14 '20 at 12:03
  • 1
    Thanks you so much @RiggsFolly! That really helps! I managed to find the issue from the question above, but your info would certainly help me over time! – Costin May 14 '20 at 13:11

0 Answers0