Jump to content
Abel1216

Alerts issue (Boostrap, Sweet alerr)

Recommended Posts

My boostrap alerts is not displaying.

The codes works if the login details are correct and also works if login details are wrong but refuses to show the error login info. My codes are

   <?php 
include 'db.php';
error_reporting(E_ALL | E_WARNING | E_NOTICE);

ini_set('display_errors', TRUE);

 if(isset($_POST['submit']))
 {
     
$msg2 ='<div class="bs-example"> 
    <div class="alert alert-warning alert-dismissible fade show">
        <strong>Error!</strong> Invalid. Login.
        <button type="button" class="close" data-dismiss="alert">×</button>
    </div>';                    
   
 $username = $_POST['username']; 

$password = $_POST['password']; 

$username = mysqli_real_escape_string($connection, $username); 
$password = mysqli_real_escape_string($connection, $password);
 //query
$query = "SELECT * FROM customer WHERE username = '{$username}'";
 $select_user_query = mysqli_query($connection, $query); 
//select user
if(!$select_user_query)
 { 
die("QUERY FAILED". mysqli_error($connection));
 } 
 else{
     
 
//bring in database values
while($row = mysqli_fetch_array($select_user_query)) 
{ 
$db_username = $row['username']; 
$db_password = $row['password'];
$db_email = $row['email'];


if($username !== $db_username && $password !== $db_password)
 { 


echo "$msg2";

} 

else if($username == $db_username && $password == $db_password) 
{ 
    date_default_timezone_set("Africa/Lagos");
    $time = date('h:i:sa');
   $date = date('d/m/Y');
   
   $msg = " <!DOCTYPE html><body>Dear <h2> $db_username , </h2>
 <h3><font color='purple'>Your Mayor Microfinance Bank Online Bank Account was logged in today,<h2> $date at $time (GMT+1)!!</h2><b>.
 </font><br> <font color='red'>If You are not the one that Logged it in, Please Visit Your bank immediately or Call our contacts available on our home page</h3></font>.....<br></b><i><font color='blue'>MMFB</font></i>
  </body></html>

$headers = "";
$headers .= "From: Mayor Microfinance Bank(MMFB)<admin@mmfb.com.ng> \r\n";
$headers .= "Reply-To:" . $db_email. "\r\n" ."X-Mailer: PHP/" . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 


$send = mail("$db_email","LOGIN SUCCESFUL",$msg,$headers);   

   $_SESSION['login'] = $username;
                                 $_SESSION['timestamp']=time();
                                 echo ("<script>location.href='../cpanel'</script>"); 
    

  
}

}//end while
}//else end
}//submit

?>

 

 

The following code is under the head section of the html code in the same page as the code above

 

<!doctype html>
<html lang="en">

    <head>
        <meta charset="utf-8" />
        <title>Customer's Dashboard | Mayor Microfinance Bank</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta content="Online Banking For Microfinance bank Demo" name="description" />
        <meta content="MayorTech" name="author" />
        <!-- App favicon -->
        <link rel="shortcut icon" href="assets/images/favicon.ico">

        <link href="assets/libs/chartist/chartist.min.css" rel="stylesheet">

        <!-- Bootstrap Css -->
        <link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
        <!-- Icons Css -->
        <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
        <!-- App Css-->
        <link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
        
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>      

       
        
        
        
        
<style>
    .bs-example{
        margin: 20px;
    }


.footer
{
background-color:cornflowerblue;
color:white;
}
</style>

    </head>   
    

The same issue occurs with sweet alert too. Am new to coding but i cant seem to figure out my errors . thanks in advance

Share this post


Link to post
Share on other sites
Posted (edited)

Very respectfully, are you really writing code for Online Banking? I'm hoping you're just doing a college class assignment.

Edited by StevenOliver
  • Thanks 1

Share this post


Link to post
Share on other sites

Just an assignment but could be useful for me in the future so you can help me out with youe observations and coreections

Share this post


Link to post
Share on other sites

the most immediate problem is you have a logic 'hole' in the username/password check, where not all possibilities are addressed. when you use negative logic, you must complement both the conditional comparison in each term and the logic combining the terms. the complement of - if(a == b && c == d) is if(a != b || c != d). it is not if(a != b && c != d), in general, you should avoid using negative logic.

you also need to use php's password_hash() when registering/storing the initial submitted password and use password_verify() when testing if a submitted password matches the saved hashed value. also, don't use a loop to fetch the data from a query that will at most match one row. just directly fetch/test the result from the query.

lastly, the recommendations given in your last thread, less the ones that were specific to an INSERT query, apply to what you are currently doing. using those recommendations will result in the least amount of code/variables.

  • Great Answer 1

Share this post


Link to post
Share on other sites

Ok tanx. I will adjust all those. But then, is that a reason why the alert about invalid login doesnt pop out even though it fails to log  the user in?? Thanks

Share this post


Link to post
Share on other sites

Tanks so much i have realised the error. Was so stubborn to use it even before i requested for help. It now works fine. One more question..

 

I made an html form to input a details of which a token input is among. So u need to generate a token which will be sent to email of the user then you input to the token field before submission. Now i used an ajax code to load the token generation code ansynchronously which works fine. But on submission of the form, the token page still loads again, thereby generating a new token.. The html form is below and the ajax code which is in the head section.     

         Id of the send token button is box

<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#box").load("token.php");
    });
});
</script>


 

                 

<form action="" method=post">

  <label>Firstname</label>
                                    <input type="text" class="form-control" id="firstname" name="firstname" placeholder="Enter destination surname" required>
                                </div>

                                <div class="form-group">
                                          <label>Lastname</label>
                                    <input type="text" class="form-control" id="lastname" name="lastname" placeholder="Enter destination last name" required>
                                </div>

<div class="form-group">
                                          <label>Middlename</label>
                                    <input type="text" class="form-control" id="middlename" name="middlename" placeholder="Enter destination Middlename" required>
                                </div>
                                <div class="form-group">
                                          <label>Description</label>
                                    <input type="text" class="form-control" id="description" name="description"  placeholder="Enter transfer description" required>
                                </div>
                                
       <button type="button" id ="box" class="btn btn-primary w-md waves-effect waves-light">SEND TOKEN</button>                    
   <div class="form-group">      
<label>ENTER OTP<label>
        <input type="number" class="form-control" name="otp" placeholder="TOKEN" pattern="[0-9]{4}" title="Only Digits (4 digit required)" required>
          
</div>

<div class="form-group row">
                                  <div class="col-12 text-right">
                                        <button class="btn btn-primary w-md waves-effect waves-light" type="submit" name="transfer">Proceed</button>
                                    </div>
                                </div>

                                <div class="form-group mt-2 mb-0 row">
                                    <div class="col-12 mt-4">
                                        <p class="mb-0">CANCEL<a href="dash.php" class="text-primary"> Go</a></p>
                                    </div>
                                </div>

                            </form>

Thanks for your usual help!!!

Share this post


Link to post
Share on other sites

... also, make sure to have mySQL error reporting on (if you don't have them on already).

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.