I’m tiring to Pass a success message after pup checks the database and confirms the data
how do I display a message in case of a wrong password entry ,I tried many solutions with no success ,I tried using ajax solutions and JavaScript with no success as I don’t know the basics on ajax and my background in JavaScript is basic
Here’s my code
LoginTest.html
<html>
<link rel="stylesheet" href="LoginStyle.css">
<head>
<title>Login</title>
</head>
<body>
<div class="login-box">
<h2>Login</h2>
<form action="http://localhost/Test2/dbloginTest.php" method="post" name="loginform" class="loginform">
<div class="user-box">
<input type="number" name="civilid" required="">
<label>Civil ID</label>
</div>
<div class="user-box">
<input type="password" name="password" required="">
<label>Password</label>
</div>
<input type="submit" name="submit" Value="Login">
</form>
<a href="Registration.html">
<input type="submit" name="register" Value="Register">
</a>
</div>
</body>
</html>
dbloginTest.php
<?php
require 'C:WindowsSystem32vendorautoload.php';
if (isset( $_POST['submit'] ) && isset( $_POST['civilid'] ) && isset( $_POST['password'] ) ) {
$civilid = ( $_POST['civilid'] );
$password = ( $_POST['password'] );
$hashpass = "";
$return = array();
//echo extension_loaded( "mongodb" ) ? "loadedn" : "not loadedn";
$con = new MongoDBClient( 'mongodb+srv://Admin:[email protected]/?retryWrites=true&w=majority' );
// Select Database
if ( $con ) {
$db = $con->VoterDatabase;
// Select Collection
$collection = $db->Voters;
$cursor = $collection->find( array( 'civilid' => $civilid ) );
foreach ( $cursor as $row ) {
ob_start();
echo $row->password;
$hashpass = ob_get_clean();
}
if ( password_verify($password,$hashpass) ) {
echo "You Have Successully Logged In";
header( 'Location:Voters.html' );
exit;
} else {
echo "Your Civil ID or Password is Incorrect";
header( 'Location:LoginTest.html' );
exit;
}
} else {
die( "Mongo DB not connected" );
}
}
?>
2
Answers
Multiple things here :
1- FIRST : DO NOT USE HTML FILES WHEN YOU USE PHP.
it is more practical and less annoying to go all php even if your code is html only.
so I’d create another file loginTest.php and transfer all loginTest.html contents into it
**
2- SECOND : the alert of success
I recommend that you use jQuery along with jQuery UI.
after adding the script links and the UI stylesheet :
write the following
this shall give you a pop of confirmation.
more here : https://jqueryui.com/dialog/
full ajax would look like this :
3- THIRD : for the failure messages :
when you create a php file for your html page, you’d be able to easily manipulate the code to show or not some html parts as the following :
The ending result of your html page in a php file would look like this :
You can simply save all your error and success messages inside a session like so …
And then display the error message if it has been set like so …