I'm using transaction to input data in to two separate tables in my database. Everything works but I just want to know how I can display an error message of what went wrong if the user does not enter all the data required. My code is as follows:
try {
$connection->begin_transaction();
$stmt = $connection->prepare("INSERT INTO images (image, mimetype)
VALUES (?,?)");
$file = (file_get_contents($_FILES['file']['tmp_name']));
$mime = $_FILES["file"]["type"];
$stmt->bind_param("ss", $file, $mime);
$connection->query($stmt->execute());
$stmt = $connection->prepare("INSERT INTO form (time, name, homepage, email, comment) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $time, $author, $homepage, $email, $comment);
$stmt->execute();
$connection->commit();
} catch (\Exception $e) {
$connection->rollback();
echo "FAILED: " . throw $e->getMessage();
}
}
But I don´t get the "FAILED: " . throw $e->getMessage();