1

I have a simple form that inserts data into my sqlite database. It works just fine on my localhost, however, I am not getting the insert to work on my remote server. How do I get error messages if my execute() never happens or === false?

Here is my code:

if (isset($_POST["submit"])) {
    $email = $_POST["Email"];
    $name = $_POST["txt_Name"];
    $agency = $_POST["sel_Agency"];
    $subagency = $_POST["txt_SubAgency"];
    $location = $_POST["txt_Location"];

    $params = array(
        ':email' => $email,
        ':name' => $name,
        ':agency' => $agency,
        ':subagency' => $subagency,
        ':location' => $location
    );

    $stmt = $db->prepare($sql);

    if ($stmt->execute($params) === FALSE) {
        //HOW TO SHOW ERROR CODE HERE
    }
}

I tried a try-catch, but didn't get anything. However, if I echo "ERROR" for example, I get the echo ERROR on screen.... I know it isn't working also, since the db has no new rows.

Any help would be appreciated. Thanks!

jasonflaherty
  • 1,924
  • 7
  • 40
  • 82
  • Use `set_error_handler` : http://stackoverflow.com/questions/1241728/can-i-try-catch-a-warning/11206244#11206244 – Goufalite Jan 06 '16 at 15:26

1 Answers1

1

If you are using PDO, to get the last error use $db->errorCode() to get erro code and $db->errorInfo() get error info

uacaman
  • 418
  • 1
  • 5
  • 15
  • This sure is a solution, but for those who just want a light interface using the built-in SQlite3 provided with PHP. Too bad the documentation isn't efficient for such a specific needs... – Goufalite Jan 06 '16 at 15:12