To remove the message alert when the page is refreshed, you can modify your code to clear the message when the page loads.
Here's an example of how you can achieve that:
PHP:
<?php
$email_addressErr = "Email|phone is not registered!";
echo '<div id="messageAlert" class="alert alert-danger" style="display:none;"></div>';
echo '<script>
window.onload = function() {
var messageAlert = document.getElementById("messageAlert");
messageAlert.classList.add("alert-danger");
messageAlert.style.display = "block";
messageAlert.innerHTML = "' . $email_addressErr . '";
var loginButton = document.getElementById("loginButton");
loginButton.addEventListener("click", function() {
messageAlert.style.display = "none";
messageAlert.innerHTML = "";
});
// Clear the message when the page is refreshed
window.addEventListener("beforeunload", function() {
messageAlert.style.display = "none";
messageAlert.innerHTML = "";
});
}
</script>';
?>
In this example, the
window.addEventListener("beforeunload") event is used to clear the message when the page is refreshed. The event listener is triggered before the page is unloaded, allowing you to remove the message and clear its contents.
By adding this event listener, the message alert will be cleared every time the page is refreshed, ensuring that it is not displayed again after the page reloads.
To remove the message alert when the page is refreshed, you can modify your code to clear the message when the page loads.
Here's an example of how you can achieve that:
PHP:
<?php
$email_addressErr = "Email|phone is not registered!";
echo '<div id="messageAlert" class="alert alert-danger" style="display:none;"></div>';
echo '<script>
window.onload = function() {
var messageAlert = document.getElementById("messageAlert");
messageAlert.classList.add("alert-danger");
messageAlert.style.display = "block";
messageAlert.innerHTML = "' . $email_addressErr . '";
var loginButton = document.getElementById("loginButton");
loginButton.addEventListener("click", function() {
messageAlert.style.display = "none";
messageAlert.innerHTML = "";
});
// Clear the message when the page is refreshed
window.addEventListener("beforeunload", function() {
messageAlert.style.display = "none";
messageAlert.innerHTML = "";
});
}
</script>';
?>
In this example, the
window.addEventListener("beforeunload") event is used to clear the message when the page is refreshed. The event listener is triggered before the page is unloaded, allowing you to remove the message and clear its contents.
By adding this event listener, the message alert will be cleared every time the page is refreshed, ensuring that it is not displayed again after the page reload
di po nagpakita yun message na success po
<?php
include "./config/config.php";
$email_address = $password = '';
$email_addressErr = $passwordErr = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (empty($_POST['email'])) {
$email_addressErr = "Email|phone is required!";
} else {
$email_address = $_POST['email'];
}
if (empty($_POST['password'])) {
$passwordErr = "Password is required!";
} else {
$password = $_POST['password'];
}
if ($email_address && $password) { // Correct the variable name from $username to $email_address
$check_email = mysqli_query($con, "SELECT * FROM
registration WHERE email_address = '$email_address'");
$check_email_row = mysqli_num_rows($check_email);
if ($check_email_row > 0) {
while ($row = mysqli_fetch_assoc($check_email)) {
$user_id = $row['user_id'];
$db_password = $row['password'];
$db_user_type = $row['user_type'];
if ($password == $db_password) {
session_start();
$_SESSION['user_id'] = $user_id;
if ($db_user_type == '1') {
header("Location: admin/dashboard.php?login=success");
exit(); // Don't forget to exit after redirecting
} else {
header("Location: user/voucher.php?login=success");
exit(); // Don't forget to exit after redirecting
}
if (isset($_GET['login']) && $_GET['login'] == 'success') {
echo '<div class="alert alert-success">Login successful!</div>';
}