} else {
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
exit('Email is not valid!');
}
// Username doesn't exists, insert new account
if ($stmt = $con->prepare('INSERT INTO accounts (username, password, email) VALUES (?, ?, ?)')) {
// We do not want to expose passwords in our database, so hash the password and use password_verify when a user logs in.
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$stmt->bind_param('sss', $_POST['username'], $password, $_POST['email']);
$stmt->execute();
echo '<script>swal({
title: "Sukces",
text: "Pomyślnie zarejestrowano!",
icon: "success",
}).then(() => {location.reload();})</script>';
exit();
} else {
// Something is wrong with the SQL statement, so you must check to make sure your accounts table exists with all 3 fields.
echo 'Could not prepare statement!';
}
}
$stmt->close();
echo '<script>swal({
title: "Sukces",
text: "Pomyślnie zarejestrowano!",
icon: "success",
}).then(() => {location.reload();})</script>';
Zwraca kod js, który pokaże komunikat, a gdy użytkownik go zamknie przeładuje stronę.