What's new

Bakit kaya ayaw gumana

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
bakit kaya ayaw gumana nun jquery ko kapag nag ssubmit ako..

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 require!";
}else {
$password = $_POST['password'];
}
if ($username && $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'){
echo "<script>window.location. href='admin/dashboard.php';</script>";
}else {
echo "<script>window.location. href= 'user/voucher.php';</script>";
}

}else {
$passwordErr = "Password is incorrect!";
}
}
}else {
$usernameErr = "username is not registered!";
}
}
}
?>


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>login</title>
<link rel= "stylesheet" href="./css/bootstrap.css">
<link rel= "stylesheet" href="./css/style.css">
<link href="./jGrowl/jquery.jgrowl.css" rel="stylesheet" media="screen"/>
<script src="./js/bootstrap.bundle.js"></script>
<script src="./js/style.js"></script>
<script src="./ajax/sweetalert2.all.min.js"></script>
<script src="./ajax/jquery-3.7.0.min.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 method= "POST" action = "" class="p-4 p-md-5 border rounded-3 bg-body-tertiary" id = "login_form" >
<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 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>
<script>
jQuery(document).ready(function(){
jQuery("#login_form").submit(function(e){
e.preventDefault();
var formData = jQuery(this).serialize();
$.ajax({
type: "POST",
url: "logindb.php",
data: formData,
success: function(html){
if(html=='true')
{
$.jGrowl("Welcome Back!", { header: 'Access Granted' });
var delay = 2000;
setTimeout(function(){ window.location = './user/voucher.php' }, delay);
}
else
{
$.jGrowl("Please Check your username and Password", { header: 'Login Failed' });
}
}

});
return false;
});
});
</script>

</body>
<html>
 
Upon reviewing your code, I noticed a couple of issues that may be causing the jQuery code not to work properly when you submit the form.

1. Typo in the jQuery code: In the jQuery code block, you are using $.ajax to make the AJAX request. However, you have imported jQuery using the jQuery keyword. To fix this, you can change $.ajax to jQuery.ajax.

2. Incorrect URL in the AJAX request: In the AJAX request, you are sending the form data to "logindb.php" (url: "logindb.php"). However, in your PHP code, the login functionality is implemented in the same file that contains the login form. To fix this, you can change the URL to the current file name: url: "<?php echo $_SERVER['PHP_SELF']; ?>".

3. Missing jQuery library: In your HTML code, you have included the Bootstrap JavaScript library (<script src="./js/bootstrap.bundle.js"></script>), but you have not included the jQuery library before it. Since Bootstrap relies on jQuery, you need to include the jQuery library before the Bootstrap library. To fix this, move the jQuery library script tag (<script src="./ajax/jquery-3.7.0.min.js"></script>) above the Bootstrap library script tag.

Here's the updated code with the above fixes:

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 require!";
    } 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') {
                        echo "<script>window.location.href='admin/dashboard.php';</script>";
                    } else {
                        echo "<script>window.location.href= 'user/voucher.php';</script>";
                    }
                } else {
                    $passwordErr = "Password is incorrect!";
                }
            }
        } else {
            $email_addressErr = "Email is not registered!";
        }
    }
}
?>


<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>login</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
    <link rel="stylesheet" href="./css/style.css">
    <link href="./jGrowl/jquery.jgrowl.css" rel="stylesheet" media="screen" />
    <script src="./ajax/jquery-3.7.0.min.js"></script>
    <script src="./js/bootstrap.bundle.js"></script>
    <script src="./js/style.js"></script>
    <script src="./ajax/sweetalert2.all.min.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 method="POST" action="" class="p-4 p-md-5 border rounded-3 bg-body-tertiary" id="login_form">
                        <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 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 don't have an Account <a href="signup.php">Signup</a>.
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script>
        jQuery(document).ready(function() {
            jQuery("#login_form").submit(function(e) {
                e.preventDefault();
                var formData = jQuery(this).serialize();
                jQuery.ajax({
                    type: "POST",
                    url: "<?php echo $_SERVER['PHP_SELF']; ?>",
                    data: formData,
                    success: function(html) {
                        if (html == 'true') {
                            jQuery.jGrowl("Welcome Back!", { header: 'Access Granted' });
                            var delay = 2000;
                            setTimeout(function() {
                                window.location = './user/voucher.php'
                            }, delay);
                        } else {
                            jQuery.jGrowl("Please Check your username and Password", { header: 'Login Failed' });
                        }
                    }
                });
                return false;
            });
        });
    </script>

</body>

</html>

Please give this code a try and see if it resolves the issue with your jQuery code not working when you submit the form.
 
Upon reviewing your code, I noticed a couple of issues that may be causing the jQuery code not to work properly when you submit the form.

1. Typo in the jQuery code: In the jQuery code block, you are using $.ajax to make the AJAX request. However, you have imported jQuery using the jQuery keyword. To fix this, you can change $.ajax to jQuery.ajax.

2. Incorrect URL in the AJAX request: In the AJAX request, you are sending the form data to "logindb.php" (url: "logindb.php"). However, in your PHP code, the login functionality is implemented in the same file that contains the login form. To fix this, you can change the URL to the current file name: url: "<?php echo $_SERVER['PHP_SELF']; ?>".

3. Missing jQuery library: In your HTML code, you have included the Bootstrap JavaScript library (<script src="./js/bootstrap.bundle.js"></script>), but you have not included the jQuery library before it. Since Bootstrap relies on jQuery, you need to include the jQuery library before the Bootstrap library. To fix this, move the jQuery library script tag (<script src="./ajax/jquery-3.7.0.min.js"></script>) above the Bootstrap library script tag.

Here's the updated code with the above fixes:

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 require!";
    } 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') {
                        echo "<script>window.location.href='admin/dashboard.php';</script>";
                    } else {
                        echo "<script>window.location.href= 'user/voucher.php';</script>";
                    }
                } else {
                    $passwordErr = "Password is incorrect!";
                }
            }
        } else {
            $email_addressErr = "Email is not registered!";
        }
    }
}
?>


<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>login</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
    <link rel="stylesheet" href="./css/style.css">
    <link href="./jGrowl/jquery.jgrowl.css" rel="stylesheet" media="screen" />
    <script src="./ajax/jquery-3.7.0.min.js"></script>
    <script src="./js/bootstrap.bundle.js"></script>
    <script src="./js/style.js"></script>
    <script src="./ajax/sweetalert2.all.min.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 method="POST" action="" class="p-4 p-md-5 border rounded-3 bg-body-tertiary" id="login_form">
                        <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 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 don't have an Account <a href="signup.php">Signup</a>.
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script>
        jQuery(document).ready(function() {
            jQuery("#login_form").submit(function(e) {
                e.preventDefault();
                var formData = jQuery(this).serialize();
                jQuery.ajax({
                    type: "POST",
                    url: "<?php echo $_SERVER['PHP_SELF']; ?>",
                    data: formData,
                    success: function(html) {
                        if (html == 'true') {
                            jQuery.jGrowl("Welcome Back!", { header: 'Access Granted' });
                            var delay = 2000;
                            setTimeout(function() {
                                window.location = './user/voucher.php'
                            }, delay);
                        } else {
                            jQuery.jGrowl("Please Check your username and Password", { header: 'Login Failed' });
                        }
                    }
                });
                return false;
            });
        });
    </script>

</body>

</html>

Please give this code a try and see if it resolves the issue with your jQuery code not working when you submit the form.
ayaw pa rin po di kaya dahil dito
if ($db_user_type == '1') {
echo "<script>window.location.href='admin/dashboard.php';</script>";
} else {
echo "<script>window.location.href= 'user/voucher.php';</script>";
}
} else {
$passwordErr = "Password is incorrect!";
}
}
} else {
$email_addressErr = "Email is not registered!";
}
 
What error you see in your browser console log? Show us so we know what you are trying to deal with. If its jquery, or anything that sends asynchronous request see error and network logs, yan guide mo if you're doing it right based sa return response at status code.
 
What error you see in your browser console log? Show us so we know what you are trying to deal with. If its jquery, or anything that sends asynchronous request see error and network logs, yan guide mo if you're doing it right based sa return response at status code.
wala po sya error pero wala output po
 

Similar threads

Back
Top