PHP: stmt-> execute () fails but error is empty
The following snippet is in my php file which shows up as a REST interface.
(...)
if ($stmt = $connection->prepare("INSERT INTO Resource VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")){
$stmt->bind_param("sssssssii", $email, $timestamp, $title, $desc, $lat, $lng, $alt, $full, $cat);
// 1)
if($stmt->execute()){
// insertion of Resource successful
// 2)
}else{
// insertion of Resource failed
echo "INSERTION_RESOURCE_FAILED";
$stmt->close();
die;
}
(...)
The previous version, which was executed correctly, did not have two additional integer fields as parameters. I was "debugging" the php file by placing echo in there. In position 1) I got an echo back, in position 2) I didn't. This means stmt-> execute () is failing. But if it fails, why don't I get the echo of the else block? What's the best way to debug problems like this? Please note that I have checked the POST values, they are correct.
I also announced
error_reporting(E_ALL);
immediately after <?php
and
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
after each set of queries. However, the error is not repeated. What could be the problem? ~
UPDATE
As Linus mentioned, this was missing display_errors()
. So I finally found out that this is a foreign key issue. But thanks to your answer, I was finally able to debug php in some pleasenter!
source to share
So, the mistake was what was missing display_errors()
. Only after it was declared, its script returned the error line stem. In my case, it was a SQL related issue.
The following script starts:
<?php
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
// (...)
source to share