1

Following snippet is in my php-file, which figures as 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, hadn't the two additional integer fields as parameters. I "debugged" the php file by placing echos in there. At position 1) I received the echo back, at position 2) not. That means to me that the stmt->execute() fails. But if that fails, why I don't receive the echo of the else block neither? How can I better debug such issues? Note that I checked the POST values, they are correct.

I also declared

error_reporting(E_ALL);

right after <?php, and

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

after each set of query. Still, no error is echoed back. What could be the problem? ~

UPDATE

Like Linus mentioned, it was the missing display_errors(). So finally I found out that it was a issue with a foreign key. But thanks to your answer I am finally able to debug the php some pleasenter!

Valentino Ru
  • 4,964
  • 12
  • 43
  • 78
  • 3
    `error_reporting` isn't all. What about `display_errors`? It needs to be set as well. – Linus Kleen May 20 '14 at 16:40
  • Make sure that each column's type is correct, that your form elements (if any) do not contain typos and are properly named. POST variables (if any) are case-sensitive. Make sure all columns exist and that you're choosing the correct table. It could be a number and a mix of possible things/factors. However, I cringe whenever I see `$desc` this tells me that you may possibly be using an MySQL reserved word [`DESC`](http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html). To display errors, use `ini_set('display_errors', 1);` in addition to what you are presently using. – Funk Forty Niner May 20 '14 at 16:48
  • 1
    Plus, it's always best to choose actual columns to insert into. What you're presently doing is like hitting a bunch of golf balls at night, hoping they'll land into the right hole(s). – Funk Forty Niner May 20 '14 at 16:53
  • @Valentino It's good to know, the hints helped. Your question remains unanswered, though. You know, it's perfectly fine to [answer your own question](http://stackoverflow.com/help/self-answer). – Linus Kleen May 21 '14 at 06:23

1 Answers1

1

Ok so the error was in fact that the missing display_errors(). Only after declaring it the script returned a stackstrace of the error. In my case, it was a SQL-related problem.

Following is the very beginning of the script:

<?php
    ini_set("display_errors", 1);
    ini_set("track_errors", 1);
    ini_set("html_errors", 1);
    error_reporting(E_ALL);
    // (...)
Valentino Ru
  • 4,964
  • 12
  • 43
  • 78