I am working on a simple website project using php and the allows users to register/login/creates sessions/etc. and am running into an error on the try statement in the PHP code.
I have searched the forums and, similar questions have been asked but I am not really finding a solution to the question. I just need a little help figuring out why the 'try' portion is causing the error, it's not making sense.
I am using XAMPP and PHP
Any help that can be offered would be appreciated.
Thanks
try {
$dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $sbh->prepare("INSERT INTO users (mydb_username, mydb_password)
VALUES (:mydb_username, :mydb_password)");
$stmt->bindParam(':mydb_username', $mydb_username, PDO::PARAM_STR);
$stmt->bindParam(':mydb_password', $mydb_password, PDO::PARAM_STR, 40);
$stmt->execute();
unset($_SESSION['form_token']);
$message = 'New User Added';
}
catch(Exception $e) {
if($e->getCode() == 23000) {
$message = 'Username already exists';
}
else {
$message = 'We are unable to process your request. Please try again later';
}
}
edit:
This question was marked as duplicate, however I am unable to find the solution to the problem I am having. The solution that has been associated with this question, does not contain any solution related to 'try (T-TRY)'
please review again.