0

This is my try statement

$query = "DELETEh FROM supers WHERE id = :id";
    try {
      $stmt = $conn->prepare($query);
      $stmt->bindValue(':id', $id);
      $stmt->execute();
      $_SESSION['notification'] = "Hero was deleted sucessfully";
    }

and this is the rest of the code

 catch(PDOException $e) {
$_SESSION['notification'] = "There was an error deleting hero: " . $e->getMessage();


 }
  header("Location: notification.php");
  exit;

when this runs, it tells me that the hero was deleted successfully, even though it did not because there is an extra "h" after DELETE. Could anyone explain why is this not getting into the catch block please?

Milan Toth
  • 29
  • 4

1 Answers1

1

Most likely you didn't do

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

when you opened the PDO connection. The default is PDO::ERRMODE_SILENT. $conn->prepare() will return FALSE and you need to get the reason from $conn->errorCode() or $conn->errorInfo().

Barmar
  • 741,623
  • 53
  • 500
  • 612