What's new

Bakit di na sya nag llog in

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
bakit kaya di na sya nag llog in o napupunta mismo sa dashboard.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) { // 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 {
echo "<script>var passwordIncorrect = true;</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">


</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="InputEmail1" aria-describedby="emailHelp" placeholder="Enter email | Phone Number">
<div class="error"></div>
<div class="error-message" id="emailErrorMessage"></div>
</div>
<div class="form-group mt-2">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control form-control-sm" name="password" id="InputPassword1" placeholder="Password">
<div class="error"></div>
<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>
<script>
const form = document.getElementById('loginForm');
const email = document.getElementById('InputEmail1');
const password = document.getElementById('InputPassword1');
form.addEventListener('submit', e => {
e.preventDefault();
validateInputs();

});
const setError = (element, message) => {
const formgroup = element.parentElement;
const errorDisplay = formgroup.querySelector('.error');
errorDisplay.innerText = message;
formgroup.classList.add('error');
formgroup.classList.remove('success');
}
const setSuccess = element => {
const formgroup = element.parentElement;
const errorDisplay = formgroup.querySelector('.error');
errorDisplay.innerText = '';
formgroup.classList.add('success');
formgroup.classList.remove('error');
}
const isValidEmail = email => {
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
const validateInputs = () => {
const emailValue = email.value.trim();
const passwordValue = password.value.trim();
if(emailValue === ''){
setError(email, 'Email Address is required');
}else if (!isValidEmail(emailValue)){
setError(email, 'Provide a valid email address');
}else {
setSuccess(email);
}
if(passwordValue === ''){
setError(password, 'Password is required');
}else if (passwordValue.length < 8){
setError(password, 'Password must be at least 8 character.');
}else {
setSuccess(password);
}
const emailErrorMessage = document.getElementById('emailErrorMessage');
if (emailValue && email.classList.contains('success')) {
emailErrorMessage.innerText = '';
} else if (emailValue && email.classList.contains('error')) {
emailErrorMessage.innerText = '. $email_addressErr . ';
} else {
emailErrorMessage.innerText = '';
}
if (typeof passwordIncorrect !== 'undefined' && passwordIncorrect) {
const passwordErrorDisplay = document.querySelector('#InputPassword1').parentElement.querySelector('.error');
passwordErrorDisplay.innerText = 'Password is incorrect!';
passwordErrorDisplay.parentElement.classList.add('error');
passwordErrorDisplay.parentElement.classList.remove('success');
passwordIncorrect = false; // Reset the variable
}
}
</script>
</body>
</HTMl:5>
 
Based on the code you provided, there are a few possible reasons why the user is not being redirected to dashboard.php:

1. Database Connection: Make sure that the $con variable in the mysqli_query function is properly connected to your database. Check your config.php file to ensure that the database credentials are correct.

2. SQL Query: Verify that the SQL query is retrieving the correct data from the database. Double-check the table name and column names to ensure they match your database structure.

3. Session Start: Ensure that the session_start() function is placed at the beginning of your PHP file. This function must be called before any output is sent to the browser.

4. File Paths: Confirm that the file paths in the header() function are correct. Check the file structure of your project to ensure that the paths to dashboard.php files are accurate.

5. User Type: Verify that the user_type column in the registration table is properly set and matches the condition in the PHP code. Make sure the value of $db_user_type is either '1' (admin) or something else (user).

6. Exit After Redirect: It is important to include the exit() function after the header() function to ensure that the script stops executing and the redirect occurs immediately.

By checking and addressing these possible issues, you should be able to determine why the user is not being redirected to dashboard.php and fix the problem accordingly.
 
Based on the code you provided, there are a few possible reasons why the user is not being redirected to dashboard.php:

1. Database Connection: Make sure that the $con variable in the mysqli_query function is properly connected to your database. Check your config.php file to ensure that the database credentials are correct.

2. SQL Query: Verify that the SQL query is retrieving the correct data from the database. Double-check the table name and column names to ensure they match your database structure.

3. Session Start: Ensure that the session_start() function is placed at the beginning of your PHP file. This function must be called before any output is sent to the browser.

4. File Paths: Confirm that the file paths in the header() function are correct. Check the file structure of your project to ensure that the paths to dashboard.php files are accurate.

5. User Type: Verify that the user_type column in the registration table is properly set and matches the condition in the PHP code. Make sure the value of $db_user_type is either '1' (admin) or something else (user).

6. Exit After Redirect: It is important to include the exit() function after the header() function to ensure that the script stops executing and the redirect occurs immediately.

By checking and addressing these possible issues, you should be able to determine why the user is not being redirected to dashboard.php and fix the problem accordingly.
simula lang nman nun nilagyan ko ng javascript
 
simula lang nman nun nilagyan ko ng javascript
Based on the code you provided, it seems that you have added some JavaScript code for form validation. However, the issue is not related to the JavaScript code itself. The problem lies in the PHP code.

Upon checking your PHP code, I noticed a few areas that may be causing the issue:

1. Database Connection: Make sure that the config.php file is correctly included and that the $con variable is properly connected to your database. Double-check your database credentials to ensure they are correct.

2. SQL Query: Verify that the SQL query is retrieving the correct data from the database. Check the table name and column names to ensure they match your database structure. Also, ensure that the registration table exists and contains the required columns.

3. Session Start: Ensure that session_start() is placed at the very beginning of your PHP file, before any output is sent to the browser. This ensures that sessions can be properly started and used.

4. File Paths: Check the file paths in the header() function's Location parameter. Make sure the paths to dashboard.php files are correct and accessible from the current file.

5. User Type: Verify that the user_type column in the registration table is correctly set and matches the condition in the PHP code. Confirm that the values for user_type are either '1' (admin) or something else for regular users.

6. Exiting After Header Redirect: After using the header() function to redirect to a different page, make sure to include exit(); immediately after to halt further execution of the script.

By reviewing and addressing these potential issues, you should be able to determine why the user is not being redirected to the desired page and resolve the problem.
 
Based on the code you provided, it seems that you have added some JavaScript code for form validation. However, the issue is not related to the JavaScript code itself. The problem lies in the PHP code.

Upon checking your PHP code, I noticed a few areas that may be causing the issue:

1. Database Connection: Make sure that the config.php file is correctly included and that the $con variable is properly connected to your database. Double-check your database credentials to ensure they are correct.

2. SQL Query: Verify that the SQL query is retrieving the correct data from the database. Check the table name and column names to ensure they match your database structure. Also, ensure that the registration table exists and contains the required columns.

3. Session Start: Ensure that session_start() is placed at the very beginning of your PHP file, before any output is sent to the browser. This ensures that sessions can be properly started and used.

4. File Paths: Check the file paths in the header() function's Location parameter. Make sure the paths to dashboard.php files are correct and accessible from the current file.

5. User Type: Verify that the user_type column in the registration table is correctly set and matches the condition in the PHP code. Confirm that the values for user_type are either '1' (admin) or something else for regular users.

6. Exiting After Header Redirect: After using the header() function to redirect to a different page, make sure to include exit(); immediately after to halt further execution of the script.

By reviewing and addressing these potential issues, you should be able to determine why the user is not being redirected to the desired page and resolve the problem.
kapag tinatanggal ko ito
"e.preventDefault();"
pumasok na sya pero yun validation ko naman di gumagana anu po alternate na pwede gamitin dyan po
 
kapag tinatanggal ko ito
"e.preventDefault();"
pumasok na sya pero yun validation ko naman di gumagana anu po alternate na pwede gamitin dyan po
If you remove the e.preventDefault() function, the form will be submitted and the page will reload. However, this will bypass your JavaScript form validation code.

To maintain the form validation while allowing the form submission, you can modify your code by adding a conditional statement to check if the form inputs are valid before submitting the form.

Here's an example of how you can modify your code:

JavaScript:
form.addEventListener('submit', e => {
    // Validate inputs
    validateInputs();
    
    // Check if any errors exist
    if (document.querySelectorAll('.error').length > 0) {
        e.preventDefault(); // Prevent form submission if there are errors
    }
});

With this modification, the form will only be submitted if there are no validation errors. If there are errors, the preventDefault() function will be called to prevent the form from being submitted.

By making this change, you can
 
If you remove the e.preventDefault() function, the form will be submitted and the page will reload. However, this will bypass your JavaScript form validation code.

To maintain the form validation while allowing the form submission, you can modify your code by adding a conditional statement to check if the form inputs are valid before submitting the form.

Here's an example of how you can modify your code:

JavaScript:
form.addEventListener('submit', e => {
    // Validate inputs
    validateInputs();
   
    // Check if any errors exist
    if (document.querySelectorAll('.error').length > 0) {
        e.preventDefault(); // Prevent form submission if there are errors
    }
});

With this modification, the form will only be submitted if there are no validation errors. If there are errors, the preventDefault() function will be called to prevent the form from being submitted.

By making this change, you can
di sya tumutuloy sa page
 

Similar threads

Back
Top