1

I'm using MySQLi prepare statements in php. The exact same code works on my local machine, but fails on the online server (it doesn't insert into the database table). I'm a server noob, so I don't know if there's a setting I need to configure or not. The else branch in the following code I got from another SO question, but it's not returning any errors. I have the following at the top of my php file:

error_reporting(E_ALL);
ini_set('display_errors', 1);

edit to add: $conn->prepare(....) is returning false

$conn = new mysqli($SERVER, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

if ($stmt = $conn->prepare("INSERT INTO tblTasks (taskID, blockNumber, transactionID, tasker, permlink, title, price, location, currency, tags, `status` ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
    $stmt->bind_param("sssssssssss", $taskID, $blockNumber, $transactionID, $tasker, $permlink, $taskTitle, $taskPrice, $location, $currency, $tags, $status);
    if(!$stmt->execute()) {
        die("Insertion failed.");
    }
    $stmt->close();
} else {
    $error = $conn->errno . ' ' . $conn->error;
    echo $error;
}
erv
  • 593
  • 8
  • 27
  • 3
    Since it was the call to `$conn->prepare` that failed, you need to echo `$conn->errno` and `$conn->error` as `$stmt` will be `false`, not an object (hence the error you are seeing) – Nick Mar 30 '19 at 02:25
  • @Nick, nup, still getting the same 'property of a non-object' error. – erv Mar 30 '19 at 02:34
  • I notice the error is occurring on multiple lines (59 and 86) have you corrected all those lines of code? – Nick Mar 30 '19 at 02:37
  • Ah good catch. I missed that. – erv Mar 30 '19 at 02:42
  • @Nick it's not reporting any errors now. I will update the question with the latest code – erv Mar 30 '19 at 02:50
  • Try an explicit `COMMIT` – Pinke Helga Mar 30 '19 at 03:57
  • Where/how do I use that, @Quasimodo'sclone? I tried using this notation - https://www.w3schools.com/Php/func_mysqli_commit.asp , but that didn't do anything. Still no errors. – erv Mar 30 '19 at 04:22
  • If the DBMS is not configured with `autocommit`, depending on the storage engine DML statements like `INSERT` are not actually written and a `ROLLBACK` is performed when the session is closed. You can commit changes at any point you want, e.g. after each DML or when multiple DML statements were done successfully. https://dev.mysql.com/doc/refman/8.0/en/innodb-autocommit-commit-rollback.html – Pinke Helga Mar 30 '19 at 04:31
  • That's SQL. I need to know how to do it in PHP. The code from w3schools did nothing. – erv Mar 30 '19 at 04:42
  • 1
    Also use `mysqli_report(MYSQLI_REPORT_STRICT);` to throw exceptions on errors. https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments/22662582#22662582 – Pinke Helga Mar 30 '19 at 04:48

1 Answers1

0

Thanks to the help in the comments section I was able to implement successful error reporting, and found the error was a simple case of a capitalised table name when it shouldn't have been capitalised. On my local windows environment capitalisation is ignored, whereas on the linux development environment capitalisation is strict!

erv
  • 593
  • 8
  • 27