redirect to another page and display alert message error
i created a login form inside a modal , that the user will input his username pass and his purpose, and when success it redirectly go to homepage, Now my problem is i created another page that if the user type the wrong username or password he will be redirect to another page above the form i want to display an error alert message incorrect username or password. Can you help me work this. advance thanks.
here is the sample form that will display the error message:
<form class="needs-validation " action="#" method="post" novalidate >
<h3 class="dark-grey-text text-center">
<strong><i class="fa fa-user"></i> Login</strong>
</h3>
<hr>
<span id="error_message" class="alert alert-danger"></span>
<div class="row" style="margin-left:300px;">
<label>Date:</label>
<span id="date" name="date"></span>
</div>
<div class="row" style="margin-left:300px;">
<label>Time:</label>
<span id="clock" name="time"></span>
</div>
<div class="md-form form-sm mb-5" style="margin-top:05px;">
<i class="fa fa-user prefix"></i>
<input type="text" id="username3" name="username3" class="form-control form-control-sm " required>
<label for="modalUsername">Username</label>
<div class="invalid-feedback" style="margin-left:30px">
Enter username.
</div>
</div>
</form>
and here is my php code:
<?php
include_once ('connection.php');
if(isset($_POST['submit']))
{
$username1 = $_POST['username1'];
$password2= $_POST['password2'];
$purpose =$_POST["purpose"];
$date=date("Y-m-d");
$time=date("H:i:s");
$sql = "select * from visitor where uname = '$username1' and pass = '$password2'";
$result = mysqli_query($conn,$sql);
$count = mysqli_num_rows($result);
if ($count == 0) {
$('#error_message').html("Incorrect username or password");
header("Location:login.php");
} else {
while ($row = mysqli_fetch_array($result)) {
$username1 = $row['uname'];
$password2 = $row['pass'];
$fname=$row['fname'];
$lname=$row['lname'];
$InsertSql = "INSERT INTO visitor_att(fname,lname,uname,pass,purpose,date,timein) VALUES ('$lname','$fname',
'$username1','$password2','$purpose','$date','$time')";
$res = mysqli_query($conn, $InsertSql);
header("Location:test.php?");
}
}
}
?>
here is the sample form that will display the error message:
<form class="needs-validation " action="#" method="post" novalidate >
<h3 class="dark-grey-text text-center">
<strong><i class="fa fa-user"></i> Login</strong>
</h3>
<hr>
<span id="error_message" class="alert alert-danger"></span>
<div class="row" style="margin-left:300px;">
<label>Date:</label>
<span id="date" name="date"></span>
</div>
<div class="row" style="margin-left:300px;">
<label>Time:</label>
<span id="clock" name="time"></span>
</div>
<div class="md-form form-sm mb-5" style="margin-top:05px;">
<i class="fa fa-user prefix"></i>
<input type="text" id="username3" name="username3" class="form-control form-control-sm " required>
<label for="modalUsername">Username</label>
<div class="invalid-feedback" style="margin-left:30px">
Enter username.
</div>
</div>
</form>
and here is my php code:
<?php
include_once ('connection.php');
if(isset($_POST['submit']))
{
$username1 = $_POST['username1'];
$password2= $_POST['password2'];
$purpose =$_POST["purpose"];
$date=date("Y-m-d");
$time=date("H:i:s");
$sql = "select * from visitor where uname = '$username1' and pass = '$password2'";
$result = mysqli_query($conn,$sql);
$count = mysqli_num_rows($result);
if ($count == 0) {
$('#error_message').html("Incorrect username or password");
header("Location:login.php");
} else {
while ($row = mysqli_fetch_array($result)) {
$username1 = $row['uname'];
$password2 = $row['pass'];
$fname=$row['fname'];
$lname=$row['lname'];
$InsertSql = "INSERT INTO visitor_att(fname,lname,uname,pass,purpose,date,timein) VALUES ('$lname','$fname',
'$username1','$password2','$purpose','$date','$time')";
$res = mysqli_query($conn, $InsertSql);
header("Location:test.php?");
}
}
}
?>
Комментарии
Отправить комментарий