What's new

Bakit kaya wala lumalabas na message alert

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
bakit kaya wala lumalabas na message alert na
"Email|phone is not registered!";

ito code ko

<?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') {
$_SESSION['login_success_timestamp'] = time();
header("Location: admin/dashboard.php?login=success");
exit(); // Don't forget to exit after redirecting
} else {
$_SESSION['login_success_timestamp'] = time();
header("Location: user/dashboard.php?login=success");
exit(); // Don't forget to exit after redirecting
}

} else {
$passwordErr = "Password is incorrect!";
echo '<div id="messageAlert" class="alert alert-danger" style="display:none;"></div>';
echo '<script>
window.onload = function() {
document.getElementById("messageAlert").classList.add("alert-danger");
document.getElementById("messageAlert").style.display = "block";
document.getElementById("messageAlert").innerHTML = "' . $passwordErr . '";

document.getElementById("loginButton").addEventListener("click", function() {
document.getElementById("messageAlert").style.display = "none";
document.getElementById("messageAlert").innerHTML = "";
// Clear the message when the page is refreshed
window.addEventListener("beforeunload", function() {
messageAlert.style.display = "none";
messageAlert.innerHTML = "";
});
});
}
</script>';
}
}
} else {
$email_addressErr = "Email|phone is not registered!";

}
}
}
?>


<!DOCTYPE html>
<HTMl:5>
<head>
<title>login</title>
<link rel="stylesheet" href="../Innerjoin/css/bootstrap.css">
<link rel="stylesheet" href="../Innerjoin/css/style.css">
<script src="../Newproject/js/bootstrap.bundle.js"></script>

</head>
<body>
<div class="body-background">
<div class="container col-xl-10 col-xxl-8 px-4 py-5">
<div class="row align-items-center g-lg-5 py-5">
<div class="col-lg-7 text-center text-lg-start">
<h1 class="display-5 fw-bold lh-1 text-body-emphasis mb-2">BUREAU OF SOILS & <BR> WATER MANAGEMENT| <br> ACCOUNTING SECTION</h1>
<div class="container">
<p class="col-lg-10 fs-6 lh-1 " style ="font-family:'MerriweatherLight';"><span class="dropCaps">B</span> = <span class="dropsmall">Boost
competence on S&W resources research and development to contribute towards agricultural productivity.</span><br>
<span class="dropCaps1">S</span> = <span class="dropsmall1"> Strengthen
linkages and partnerships, and ensure mandatory compliance to relevant statutory and regulatory requirements.</span>
<br>
<span class="dropCaps2">W</span> = <span class="dropsmall2"> Work
towards effective generation, development and delivery of relevant and innovative S&W products and services.</span>
<br>
<span class="dropCaps3">M</span> = <span class="dropsmall3"> Maintain
high level of integrity and utmost professionalism, and promote welfare of all employees.</span>
</p>
</div>
</div>
<div class=" col-lg-5">
<form id="loginForm" method= "POST" action = "" class="p-4 p-md-5 border rounded-3 bg-body-tertiary">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="text" class="form-control form-control-sm" name="email" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email | Phone Number">
</div>
<div class="form-group mt-2">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control form-control-sm" name="password" id="exampleInputPassword1" placeholder="Password">
<small id="emailHelp" class="form-text text-muted">We'll never share your Password with anyone else.</small>
</div>
<div class="form-group mt-3">
<button id="loginButton" class="w-100 btn btn-sm btn-lg btn-primary" type="submit">Login</button>
</div>
<div class="text-center mt-3 fw-bold">
<small class="text-body-primary"><a href ="signup.php">Forgot Password</a>.
</div>
<hr class="my-2">
<!-- <small class="text-body-secondary">By clicking Sign up, you agree to the terms of use.</small>
<div class=" mb-3">
<label> -->
<div class="text-center fs-6 fw-bold">
<small class="text-body-secondary"> I dont have an Account <a href ="signup.php">Signup</a>.
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div id="messageAlert" class="alert alert-danger" style="display:none;"></div>
<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>
</body>
</HTMl:5>
 
Upon examining your code, I noticed a few issues that could be causing the "Email|phone is not registered!" message alert to not appear.

1. Incorrect table name: It appears that you have enclosed the table name in square brackets (registration). Square brackets are not necessary in this case, so you can remove them to make the query work properly. Replace the line:
Code:
$check_email = mysqli_query($con, "SELECT * FROM [ICODE]registration[/ICODE] WHERE email_address = '$email_address'");
with:
Code:
$check_email = mysqli_query($con, "SELECT * FROM registration WHERE email_address = '$email_address'");

2. Missing closing script tag: In the JavaScript code block where you are trying to display the error message, the closing script tag is missing. Add </script> at the end of the script block to fix this issue.

Here's the corrected code:

PHP:
<?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) {
        $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') {
                        $_SESSION['login_success_timestamp'] = time();
                        header("Location: admin/dashboard.php?login=success");
                        exit(); // Don't forget to exit after redirecting
                    } else {
                        $_SESSION['login_success_timestamp'] = time();
                        header("Location: user/dashboard.php?login=success");
                        exit(); // Don't forget to exit after redirecting
                    }
                
                } else {
                    $passwordErr = "Password is incorrect!";
                    echo '<div id="messageAlert" class="alert alert-danger" style="display:none;"></div>';
                    echo '<script>
                    window.onload = function() {
                    document.getElementById("messageAlert").classList.add("alert-danger");
                    document.getElementById("messageAlert").style.display = "block";
                    document.getElementById("messageAlert").innerHTML = "' . $passwordErr . '";
    
                    document.getElementById("loginButton").addEventListener("click", function() {
                    document.getElementById("messageAlert").style.display = "none";
                    document.getElementById("messageAlert").innerHTML = "";
                    // Clear the message when the page is refreshed
                    window.addEventListener("beforeunload", function() {
                        messageAlert.style.display = "none";
                        messageAlert.innerHTML = "";
                    });
                });
            }
        }
    </script>';
                }
            }
        } else {
            $email_addressErr = "Email|phone is not registered!";
           
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <link rel="stylesheet" href="../Innerjoin/css/bootstrap.css">
    <link rel="stylesheet" href="../Innerjoin/css/style.css">
    <script src="../Newproject/js/bootstrap.bundle.js"></script>
</head>
<body>
    <div class="body-background">
        <div class="container col-xl-10 col-xxl-8 px-4 py-5">
            <div class="row align-items-center g-lg-5 py-5">
                <div class="col-lg-7 text-center text-lg-start">
                    <h1 class="display-5 fw-bold lh-1 text-body-emphasis mb-2">BUREAU OF SOILS & <BR> WATER MANAGEMENT| <br> ACCOUNTING SECTION</h1>
                    <div class="container">
                        <p class="col-lg-10 fs-6 lh-1 " style ="font-family:'MerriweatherLight';"><span class="dropCaps">B</span> = <span class="dropsmall">Boost
                        competence on S&W resources research and development to contribute towards agricultural productivity.</span><br>
                        <span class="dropCaps1">S</span> = <span class="dropsmall1"> Strengthen
                        linkages and partnerships, and ensure mandatory compliance to relevant statutory and regulatory requirements.</span>
                        <br>
                        <span class="dropCaps2">W</span> = <span class="dropsmall2"> Work
                        towards effective generation, development and delivery of relevant and innovative S&W products and services.</span>
                        <br>
                        <span class="dropCaps3">M</span> = <span class="dropsmall3"> Maintain
                        high level of integrity and utmost professionalism, and promote welfare of all employees.</span>
                        </p>
                    </div>
                </div>
                <div class=" col-lg-5">
                    <form id="loginForm" method= "POST" action = "" class="p-4 p-md-5 border rounded-3 bg-body-tertiary">
                        <div class="form-group">
                            <label for="exampleInputEmail1">Email address</label>
                            <input type="text" class="form-control form-control-sm" name="email" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email | Phone Number">
                        </div>
                        <div class="form-group mt-2">
                            <label for="exampleInputPassword1">Password</label>
                            <input type="password" class="form-control form-control-sm" name="password" id="exampleInputPassword1" placeholder="Password">
                            <small id="emailHelp" class="form-text text-muted">We'll never share your Password with anyone else.</small>
                        </div>
                        <div class="form-group mt-3">
                            <button id="loginButton" class="w-100 btn btn-sm btn-lg btn-primary" type="submit">Login</button>
                        </div>
                        <div class="text-center mt-3 fw-bold">
                            <small class="text-body-primary"><a href ="signup.php">Forgot Password</a>.
                        </div> 
                        <hr class="my-2">
                        <div class="text-center fs-6 fw-bold">
                            <small class="text-body-secondary"> I dont have an Account <a href ="signup.php">Signup</a>.
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div id="messageAlert" class="alert alert-danger" style="display:none;"></div>
    <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>
</body>
</html>

With these corrections, the "Email|phone is not registered!" message alert should now appear correctly when the email/phone number is not registered in the database.
 
Upon examining your code, I noticed a few issues that could be causing the "Email|phone is not registered!" message alert to not appear.

1. Incorrect table name: It appears that you have enclosed the table name in square brackets (registration). Square brackets are not necessary in this case, so you can remove them to make the query work properly. Replace the line:
Code:
$check_email = mysqli_query($con, "SELECT * FROM [ICODE]registration[/ICODE] WHERE email_address = '$email_address'");
with:
Code:
$check_email = mysqli_query($con, "SELECT * FROM registration WHERE email_address = '$email_address'");

2. Missing closing script tag: In the JavaScript code block where you are trying to display the error message, the closing script tag is missing. Add </script> at the end of the script block to fix this issue.

Here's the corrected code:

PHP:
<?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) {
        $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') {
                        $_SESSION['login_success_timestamp'] = time();
                        header("Location: admin/dashboard.php?login=success");
                        exit(); // Don't forget to exit after redirecting
                    } else {
                        $_SESSION['login_success_timestamp'] = time();
                        header("Location: user/dashboard.php?login=success");
                        exit(); // Don't forget to exit after redirecting
                    }
               
                } else {
                    $passwordErr = "Password is incorrect!";
                    echo '<div id="messageAlert" class="alert alert-danger" style="display:none;"></div>';
                    echo '<script>
                    window.onload = function() {
                    document.getElementById("messageAlert").classList.add("alert-danger");
                    document.getElementById("messageAlert").style.display = "block";
                    document.getElementById("messageAlert").innerHTML = "' . $passwordErr . '";
   
                    document.getElementById("loginButton").addEventListener("click", function() {
                    document.getElementById("messageAlert").style.display = "none";
                    document.getElementById("messageAlert").innerHTML = "";
                    // Clear the message when the page is refreshed
                    window.addEventListener("beforeunload", function() {
                        messageAlert.style.display = "none";
                        messageAlert.innerHTML = "";
                    });
                });
            }
        }
    </script>';
                }
            }
        } else {
            $email_addressErr = "Email|phone is not registered!";
          
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <link rel="stylesheet" href="../Innerjoin/css/bootstrap.css">
    <link rel="stylesheet" href="../Innerjoin/css/style.css">
    <script src="../Newproject/js/bootstrap.bundle.js"></script>
</head>
<body>
    <div class="body-background">
        <div class="container col-xl-10 col-xxl-8 px-4 py-5">
            <div class="row align-items-center g-lg-5 py-5">
                <div class="col-lg-7 text-center text-lg-start">
                    <h1 class="display-5 fw-bold lh-1 text-body-emphasis mb-2">BUREAU OF SOILS & <BR> WATER MANAGEMENT| <br> ACCOUNTING SECTION</h1>
                    <div class="container">
                        <p class="col-lg-10 fs-6 lh-1 " style ="font-family:'MerriweatherLight';"><span class="dropCaps">B</span> = <span class="dropsmall">Boost
                        competence on S&W resources research and development to contribute towards agricultural productivity.</span><br>
                        <span class="dropCaps1">S</span> = <span class="dropsmall1"> Strengthen
                        linkages and partnerships, and ensure mandatory compliance to relevant statutory and regulatory requirements.</span>
                        <br>
                        <span class="dropCaps2">W</span> = <span class="dropsmall2"> Work
                        towards effective generation, development and delivery of relevant and innovative S&W products and services.</span>
                        <br>
                        <span class="dropCaps3">M</span> = <span class="dropsmall3"> Maintain
                        high level of integrity and utmost professionalism, and promote welfare of all employees.</span>
                        </p>
                    </div>
                </div>
                <div class=" col-lg-5">
                    <form id="loginForm" method= "POST" action = "" class="p-4 p-md-5 border rounded-3 bg-body-tertiary">
                        <div class="form-group">
                            <label for="exampleInputEmail1">Email address</label>
                            <input type="text" class="form-control form-control-sm" name="email" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email | Phone Number">
                        </div>
                        <div class="form-group mt-2">
                            <label for="exampleInputPassword1">Password</label>
                            <input type="password" class="form-control form-control-sm" name="password" id="exampleInputPassword1" placeholder="Password">
                            <small id="emailHelp" class="form-text text-muted">We'll never share your Password with anyone else.</small>
                        </div>
                        <div class="form-group mt-3">
                            <button id="loginButton" class="w-100 btn btn-sm btn-lg btn-primary" type="submit">Login</button>
                        </div>
                        <div class="text-center mt-3 fw-bold">
                            <small class="text-body-primary"><a href ="signup.php">Forgot Password</a>.
                        </div>
                        <hr class="my-2">
                        <div class="text-center fs-6 fw-bold">
                            <small class="text-body-secondary"> I dont have an Account <a href ="signup.php">Signup</a>.
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div id="messageAlert" class="alert alert-danger" style="display:none;"></div>
    <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>
</body>
</html>

With these corrections, the "Email|phone is not registered!" message alert should now appear correctly when the email/phone number is not registered in the database.
di pa rin nag papakita yun message alert
 

Similar threads

Back
Top