Robert Ross Robert Ross - 1 month ago 7
PHP Question

Login form in modal with Bootstrap and php not working

I am trying to implement a simple login functionality on my project, but for some reason it doesn't work as expected(or at all).
I am not able to get the data from the

name
attributes from the php form, so I can proceed to the login. For some reason the data is not fetched at all. I am new to web development, so please help.

Here is my modal containing the form

<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">LOGIN</h4>
</div>
<div class="modal-body">
<p>Please, enter your login details.</p>
</div>


<form method="POST" action="homePage.php">
<div class="row">
<div class="col-xs-7">
<input type="text" name="txtUserEmail" class="form-control modalForm" id="usr" placeholder=" CPR 000000-0000">
</div>
</div>
<div class="row">
<div class="col-xs-7">
<input type="password" class="form-control modalForm" name="txtUserPassword" id="pwd" placeholder="Password">
</div>
</div>
<button type="button" class="btn btn-info modalForm" data-dismiss="modal">Login</button>
</form>


<div class="modal-footer">

</div>
</div>


And here is the php for the login :

<?php


session_start();

$string = file_get_contents("users.json");

$json_a = json_decode($string, true);

$arr = array();
foreach ($json_a as $json_r) {
if ($json_r['userName']==$_POST["txtUserEmail"] && $json_r['pass']==$_POST["txtUserPassword"] ) {
file_put_contents("prods.json",$json_r['userName']);

if ($json_r['isAdmin']==1) {
$_SESSION['userEmail'] = $json_r['userName'];
header('location: adminPage.php');
# code...
}else{
$_SESSION['userEmail'] = $json_r['userName'];
header('location: patientPage.php');
}
}

}
?>


Any input will be appreciated.

Answer

Try This

<div class="modal-content">
<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal">&times;</button>
  <h4 class="modal-title">LOGIN</h4>
</div>
<div class="modal-body">
  <p>Please, enter your login details.</p>
</div>


<form method="POST" action="homePage.php">
  <div class="row">
    <div class="col-xs-7">
      <input type="text" name="txtUserEmail" class="form-control modalForm" id="usr" placeholder=" CPR 000000-0000">
    </div>
  </div>
  <div class="row">
    <div class="col-xs-7">
     <input type="password" class="form-control modalForm" name="txtUserPassword" id="pwd" placeholder="Password">
    </div>
  </div>
  <button type="submit" class="btn btn-info modalForm" >Login</button>
</form>


<div class="modal-footer">

</div>