0

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.

  • The linked question gives you an overdrive on how to fix PHP syntax errors, which you definitely have. In this case, the `try` is unexpected, which means that there's likely an issue on the preceding line in your code. – andrewsi Nov 30 '15 at 01:02
  • That gives me more insight, thank you @andrewski – noknowledge Nov 30 '15 at 01:12

0 Answers0