Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP – How can i show notification bar(Error) when user added wrong username and password

I want to show a notification bar which will display error when user added wrong username and password

I am a beginner in PHP.

I am trying this code and i think there could be a if condition that will be used but didn’t know how to write it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

the database is connected and is working fine. when entered the write username and password it works

<?php

session_start();

include '_database.php';

 $alertShow = false;


if($_SERVER["REQUEST_METHOD"] == 'POST'){

$user = $_POST[ 'user'];
$password = $_POST['pass'];

$user = stripcslashes($user);
$password = stripcslashes($password);

$user = mysqli_real_escape_string($conn , $user);

$password = mysqli_real_escape_string($conn , $password);


$sql = "select * from signin where user_name = '$user' and password = '$password'";  


$result = mysqli_query($conn , $sql);

$row = mysqli_fetch_array($result , MYSQLI_ASSOC);

$count = mysqli_num_rows($result);

if($count==1 ){
    
    session_start();
    $alertShow == false;
    header("Location: index.php?$user");
    
    exit();

}else{
    
    header("Location: login.php?$user");

   
    
}

}






if($alertShow==true){

    echo $alert = '<div class="alert alert-primary" role="alert">
     This is a primary alert—check it out!
     </div>';
 
 }
 

?>

>Solution :

    <?php
session_start();

include '_database.php';

if($_SERVER["REQUEST_METHOD"] == 'POST'){

$user = $_POST[ 'user'];
$password = $_POST['pass'];

$user = stripcslashes($user);
$password = stripcslashes($password);

$user = mysqli_real_escape_string($conn , $user);

$password = mysqli_real_escape_string($conn , $password);


$sql = "select * from signin where user_name = '$user' and password = '$password'";  


$result = mysqli_query($conn , $sql);

$row = mysqli_fetch_array($result , MYSQLI_ASSOC);

$count = mysqli_num_rows($result);

if($count==1 ){
    
    header("Location: index.php?$user");
    
    exit();

}else{
    
    echo '<div class="alert alert-primary" role="alert">
     This is a primary alert—check it out!
     </div>';   
    
}

}
?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading