What's new

Message success

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
bakit po kaya di nagpakita yun message na success kapag nag lolog in ako

<?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 (isset($_GET['login']) && $_GET['login'] == 'success') {
echo '<div class="alert alert-success">Login successful!</div>';
}
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
}
 
Based on the code provided, it seems that the message "Login successful!" is only displayed when the URL parameter login is set to "success". However, there is no code that sets this parameter to "success" when the login is successful.

To fix this issue, you can add the parameter login=success to the URL when redirecting to the desired page after successful login. Here's an example:

PHP:
header("Location: admin/dashboard.php?login=success");

Make sure to also add the parameter when redirecting to the user page:

PHP:
header("Location: user/voucher.php?login=success");

By doing this, the message "Login successful!" will be displayed when the user is redirected to the desired page after successful login.
 
try mo mag lagay $loginSuccess = true; tapos dun sa may html file mo tawagin mo yung gamit yung if else $loginSuccess sa loob nyan yung echo alert na "LOGIN SUCESSFUL " . parang ganito

<?php
if($loginSuccess) {
echo '<div class="alert alert-success">Login successful!</div>';
}?>
 
try mo mag lagay $loginSuccess = true; tapos dun sa may html file mo tawagin mo yung gamit yung if else $loginSuccess sa loob nyan yung echo alert na "LOGIN SUCESSFUL " . parang ganito

<?php
if($loginSuccess) {
echo '<div class="alert alert-success">Login successful!</div>';
}?>
ok po sir maraming salamat po
 
nag redirect ka kasi lods
(header("Location)

kaya nawala yung
div.alert.alert-success
na inecho mo.

dapat wala munang output statement before header()

tapos lagay mo sa redirection file

$isLoginSucces = $_GET['login'] ?? '0';

sa markup
<?php
if($isLoginSucces == 'success') {
echo '<div class="alert alert-success">Login successful!</div>';
}?>


in your use case i think its better to use $_SESSION['message']
 

Similar threads

Back
Top