pbismad;11063199 wrote:Unless a database error has meaning to your application and your application is responsible for handling it, such as for a value that causes a duplicate key/value error, and you want to tell the visitor a value they tried couldn't be used
For duplicate keys ect. wouldn't that mean you haven't normalized the database to at least 3rd normal form? If I understand database integrity correctly using UNIQUE should prevent that no?
pbismad;11063199 wrote:
you should not catch exceptions in your application code and you should not have code that unconditionally echos the raw database errors out on a page, as this gives hackers useful information when they deliberately trigger errors.
So it would be like validation for lack of a better definition? In example:
if(empty($errors))
{
try
{
$success = ["message" => "Please check your Email address to activate your account"];
$database->query('INSERT INTO username (username_id, password ,activecode, joinedDate, eMail, active, img_name, img_path, img_type)
VALUES
(:username, :password,:activationCode, NOW(), :email, 0, :filename, :filepath, :filetype)');
$database->bind(':username', $username);
$database->bind(':email', $email);
$database->bind(':password', password_hash($post['password'], PASSWORD_DEFAULT));
$database->bind(':activationCode', $activationCode);
$database->bind(':filename', $filename);
$database->bind(':filepath', $filepath);
$database->bind(':filetype', $filetype);
$database->execute();
$code = 'http://gotsocial.co.uk/gotsocial/active.php?activecode=' . $activationCode . '.
';
$to = $post['email'];
$subject = 'GOT Social';
$from = "register@gotsocial.co.uk";
$result = mail($to, $subject, $code, "From: $from");
}
catch(Exception $e)
{
$errors[] = ["name" => "username", "error" => "Username or E-mail may already be registered"];
}
}
pbismad;11063199 wrote:
If you let php catch the exceptions, php will use its error_reporting, display_errors, and log_errors settings to control what happens with the actual error information. You can then eliminate those try/catch blocks and just by setting the display_errors and log_errors settings, you can switch from displaying errors, during learning, development, and testing, to logging errors, when on a live server.
Something like this? (not sure I follow 100% in honesty)
error_reporting(-1); // reports all errors
ini_set("display_errors", "1"); // shows all errors
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");