title: signin and signup bootstrap modals with php and mysql
body: <p>I have two bootstrap modals one for sign in and another one for signup. Inside each of them, there is a form that handles the action (I'm not doing stuff in a separate page).<br>
  A connection page is included in this project to handle the connection success and failure.<br>
  First, they were working but after adding the session they don't perform anything and just redirect me to the same page I will put the code below if anyone can tell me what causes the problem or were is the problem in my code I would be glad .. regards   </p>
  
  <pre><code>session_start();
      if(isset($_SESSION['USERNAME']))
      {
          header('Location:home.php');
      }
  
      if($_SERVER['REQUEST_METHOD'] == 'POST')
      {
          if(isset($_POST['signin']))
          {
              // Get Variables From The Form By Their Name Attributes
              $username = $_POST['emailOrMobile'];
              $password = password_hash($_POST['password'],PASSWORD_DEFAULT);
  
              // Check if the user exist in database
              $stmt = $con-&gt;prepare("select ID,firstName,email,mobile,password,status from users where (email=? or mobile =?) and password=?");
              $stmt-&gt;execute(array($username,$username,$password));
              $info=$stmt-&gt;fetch();
              $count=$stmt-&gt;rowCount();
  
              if($count&gt;0)
              {
                  if(!$info["status"]==0)
                  {
                      $_SESSION['ID'] = $info["ID"];
                      $_SESSION['USERNAME'] = $info["firstName"];
                      header('Location:home.php');
                      exit();
                  }
                  else
                  {
                      $_SESSION['ID'] = $info["ID"];
                      $_SESSION['USERNAME'] = $info["firstName"];
                      $_SESSION['mobile'] = $info["mobile"];
                      header('Location:register.php');
                      exit();
                  }
              }
              else
              {
                  header('Location:errors.php');
                  exit();
              }
          }
          else if(isset($_POST['signup']))
          {
              // Get Variables From The Form By Their Name Attributes
              $firstName = $_POST['firstName'];
              $lastName = $_POST['lastName'];
              $email = $_POST['email'];
              $mobile = $_POST['mobile'];
              $password = password_hash($_POST['password'],PASSWORD_DEFAULT);
              $birthDate = $_POST['birthDate'];
              if(!empty($_POST['gender']))
              {
                  $gender = $_POST['gender'];
              }
              else
              {
                  $gender = 0;
              }
  
              // Generating serial token for account verification
              $tokens = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
              $serial = '';
              for ($i = 0; $i &lt; 4; $i++) 
              {
                  for ($j = 0; $j &lt; 5; $j++) 
                  {
                      $serial .= $tokens[rand(0, 35)];
                  }
                  if ($i &lt; 3) {
                      $serial .= '-';
                  }
              }
  
              // Validate The Form
              $formErrors=array(); // Empty Array Defined For Containing Error Messages Of Empty Inputs
              if(strlen($firstName) &lt; 3)
              {
                  $formErrors[]='first Name can not be less than &lt;strong&gt;3 characters&lt;/strong&gt;';  
              }
              if(strlen($firstName) &gt; 255)
              {
                  $formErrors[]='first Name can not be greater than &lt;strong&gt;255 characters&lt;/strong&gt;'; 
              }
              if(empty($firstName))
              {
                  $formErrors[]='First Name can not be &lt;strong&gt;empty&lt;/strong&gt;';   
              }
              if(strlen($lastName) &lt; 3)
              {
                  $formErrors[]='Last Name can not be less than &lt;strong&gt;3 characters&lt;/strong&gt;';   
              }
              if(strlen($lastName) &gt; 255)
              {
                  $formErrors[]='Last Name can not be greater than &lt;strong&gt;255 characters&lt;/strong&gt;';  
              }
              if(empty($lastName))
              {
                  $formErrors[]='Last Name can not be &lt;strong&gt;empty&lt;/strong&gt;';    
              }
              if(strlen($mobile) &gt; 12)
              {
                  $formErrors[]='Mobile number can not be greater than &lt;strong&gt;12 characters&lt;/strong&gt;';
              }
              if(empty($mobile))
              {
                  $formErrors[]='Mobile can not be &lt;strong&gt;empty&lt;/strong&gt;';   
              }
              if(empty($email))
              {
                  $formErrors[]='Email can not be &lt;strong&gt;empty&lt;/strong&gt;';    
              }
              if(empty($birthDate))
              {
                  $formErrors[]='Birth Date can not be &lt;strong&gt;empty&lt;/strong&gt;';   
              }
  
              // If There Is No Error Procced The Insert Operation
              if(empty($formErrors))
              {
                  // Insert User Info In Database
                  $stmt = $con-&gt;prepare("insert into users (ID , firstName , lastName , email , mobile , password , birthDate , gender , status , token) values (DEFAULT , :ufirstName , :ulastName , :uemail , :umobile , :upassword , :ubirthDate , :ugender , 0 , :utoken)");
                  $stmt-&gt; execute(array(
                      'ufirstName' =&gt; $firstName,
                      'ulastName' =&gt; $lastName,
                      'uemail' =&gt; $email,
                      'umobile' =&gt; $mobile,
                      'upassword' =&gt; $password,
                      'ubirthDate' =&gt; $birthDate,
                      'ugender' =&gt; $gender,
                      'utoken' =&gt; $serial
                  )); // Here The Execution Of The Query Ends After Inserting The Variables Inside The Values Defined Teporerly In Query
                  //$_SESSION['ID'] = $info["ID"];
                  $_SESSION['USERNAME'] = $firstName;
                  $_SESSION['mobile'] = $mobile;
                  header('Location:register.php');
                  exit();
              }
          }
      }   
  </code></pre>
  
  <p>and this is the modals code:  </p>
  
  <pre><code>&lt;!-- Signin Popup model --&gt;
  &lt;div class="modal fade" id="modal-login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                  &lt;h3 class="text-center"&gt;LOGIN&lt;/h3&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;
                  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="POST"&gt;
                      &lt;div&gt;
                          &lt;input type="text" name="emailOrMobile" required="" autocomplete="off" /&gt;
                          &lt;label&gt;Email or Mobile&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="password" name="password" required="" autocomplete="off" /&gt;
                          &lt;label&gt;Password&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;button type="submit" class="submit-btn btn btn-block" name="signin"&gt;Signin&lt;/button&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;p&gt;Dont have an account?&lt;/p&gt;
                  &lt;button id="join-trigger" class="signup-trigger-btn btn"&gt;Signup&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;!-- Signup Popup model --&gt;
  &lt;div class="modal fade" id="modal-signup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                  &lt;h3 class="text-center"&gt;Signup&lt;/h3&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;
                  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="POST"&gt;
                      &lt;div&gt;
                          &lt;input type="text" name="firstName" required="" autocomplete="off"&gt;
                          &lt;label&gt;First Name&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="text" name="lastName" required="" autocomplete="off"&gt;
                          &lt;label&gt;Last Name&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="email" name="email" required="" autocomplete="off"&gt;
                          &lt;label&gt;Email&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="tel" name="mobile" required="" autocomplete="off"&gt;
                          &lt;label&gt;Mobile&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="password" name="password" required="" autocomplete="off"&gt;
                          &lt;label&gt;Password&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="text" name="birthDate" required="" id="datetimepicker"&gt;
                          &lt;label&gt;Birth Date&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;div id="gender-div"&gt;
                              &lt;label&gt;Gender&lt;/label&gt;
                              &lt;label class="gender"&gt;Male&lt;/label&gt;
                              &lt;label class="gender"&gt;Female&lt;/label&gt;
                              &lt;input type="checkbox" name="gender" value="1" /&gt;       
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;button type="submit" class="submit-btn btn btn-block" name="signup"&gt;SIGN UP&lt;/button&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;p&gt;Already have an account?&lt;/p&gt;
                  &lt;button id="login-trigger" class="signin-trigger-btn btn"&gt;Signin&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>