MySQL Forums
Forum List  »  PHP

2 Questions, PHP Login Validation Error message not showing and showing PHP echo in bootstrap div
Posted by: Touqeer Anjum
Date: September 23, 2017 08:59PM

Hi all,

I have the below code where there are 2 issues.

1 - I'm trying to validate the login/password of user from mysql and there seems to be this issue where ONLY if the email match was found in the db and the password was wrong the error message shows up, if the email was not fun din the db, even though I have set an error message it does not show.

2 - I'm trying to show a PHP session data inside of an empty DID but it won't show for some reason, I tried both ways, by adding <?php ?> and then the data inside and by adding echo and tags of the html inside php, nether ways work, any suggestions ?

<?php
if (isset($_SESSION['sesName']))
{
echo '<div class="row">
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
<div class="panel-body">
<form role="form">
<fieldset>
<div class="form-group">';
echo '<div class = "alert alert-success fade in">Welcome ' . $_Session['sesName'] . '"</div>';
'</div>
</fieldset>
</form>
</div>
</div>
</div>';
}
?>
<div class="row">
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">LOGIN</div>
<div class="panel-body">
<form role="form" method="POST" action="">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="E-mail" name="lemail" type="text" autofocus="">
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="lpass" type="password" value="">
</div>
<div class="checkbox">
</div>
<input type ="submit" class="btn btn-primary" value="LOGIN"> <input type ="button" onclick="location.href='registration.php'" class="btn btn-primary" value="REGISTRATION">
</fieldset>
</form>
</div>
</div>
</div>
</div>

<?php

session_start();


$server = "localhost";
$user = "root";
$pwd = "";
$sql_db = "cabcustomers";
$lname = isset($_POST['lemail']);
$lpass = isset($_POST['lpass']);
$dbname;

$conn = @mysqli_connect($server,$user,$pwd,$sql_db);

if (!$conn)
{
die("Connection to Database has failed: " . mysqli_connect_error());
}

if (isset ($_POST["lemail"]) && isset ($_POST["lpass"]))
{
$lemail = $_POST["lemail"];
$lpass = $_POST["lpass"];

$query = "select email, password from customer where email='$lemail' and password = '$lpass'";
$result = mysqli_query($conn, $query);

if ($row = mysqli_fetch_assoc($result) > 0)
{
$dbname = $row["email"];
$dbpass = $row["password"];
$passchk = password_verify($lpass, $dbpass);

if ($lemail == $dbname && $passchk == $dbpass)
{
$_SESSION['sesName'] = $dbname;
header('location:booking.php');
}
else
{
echo '<div class="row">
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
<div class="panel-body">
<form role="form">
<fieldset>
<div class="form-group">';
echo '<div class = "alert alert-danger alert-dismissable fade in"><button type = "button" class = "close" data-dismiss = "alert" aria-hidden = "true">&times;</button>This email is not registered or the password is incorrect, pleae try again or consider registering</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>';
}
}
elseif (empty($lemail) || empty($lpass))
{
echo '<div class="row">
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
<div class="panel-body">
<form role="form">
<fieldset>
<div class="form-group">';
echo '<div class = "alert alert-info alert-dismissable fade in"><button type = "button" class = "close" data-dismiss = "alert" aria-hidden = "true">&times;</button>No email or password entered</div>';
'</div>
</fieldset>
</form>
</div>
</div>
</div>';
}
}
mysqli_close($conn);
?>

Thank You All for your help.

Options: ReplyQuote


Subject
Written By
Posted
2 Questions, PHP Login Validation Error message not showing and showing PHP echo in bootstrap div
September 23, 2017 08:59PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.