What am I doing wrong? (PHP and MYSQL) -


i have code here have been using in several projects without issue. thing i've changed using mamp instead of xampp this.

the problem i'm facing code runs without errors (it runs through if else statement in login functions, nothing happens (it doesn't redirect user) , if input wrong details shows no records found. can guide me through please?

login.php

<?php session_start(); if (!empty($_session['admin'])&&!empty($_session['type'])) {     header("location: admin/index.php"); } elseif (!empty($_session['user'])&&!empty($_session['type'])) {     header("location: user/"); } ?>   <!--===== login =====--> <section id="login" class="padding" style="padding-top: 200px;">   <div class="container">     <div class="row">       <div class="col-md-12 text-center">         <div class="profile-login">           <div class="login_detail" style="margin-top:-50px;">             <!-- tab panes -->             <div class="tab-content">              <h1>                 <?php                     extract($_post);                     if (isset($btn) && !empty($username) && !empty($password)) {                         require 'includes/users.php';                         login();                     }                 ?>             </h1>               <div role="tabpanel" class="tab-pane fade in active" id="profile">                 <h2>login below</h2>                 <div class="agent-p-form">                   <div class="row">                     <form class="callus" action="login.php"  method="post">                       <div class="col-md-12">                         <div class="single-query">                           <input name="username"  type="text" class="keyword-input" placeholder="username" required>                         </div>                         <div class="single-query">                           <input name="password" type="password" class="keyword-input" placeholder="password">                         </div>                       </div>                       <div class="col-md-12 col-sm-12 col-xs-12 text-center">                         <div class="query-submit-button">                           <button name="btn" type="submit" class="btn_fill">login</button>                         </div>                       </div>                     </form> 

users.php

<?php  function login() {   require 'connect.php';     $username = mysqli_real_escape_string($con,$_post['username']);     $password = mysqli_real_escape_string($con,$_post['password']);     $pass = $password;     $sql = "select * `users` `username`='$username' , `password`='$pass'";     $query = mysqli_query($con,$sql);     $row = mysqli_num_rows($query);     if ($row == 0) {         echo "<b style='font-size:12px; color:#fff'>wrong username/password combination</b>";     }     elseif ($row == 1) {         $fetch = mysqli_fetch_array($query);         $type = $fetch['user_role'];         $name = $fetch['username'];         if ($type == "administrator") {             @session_start();             $_session['user_role'] = $type;             $_session['admin'] = $name;             header("location: admin/index.php");         }          elseif ($type=="user") {             @session_start();             $_session['user_role'] = $type;             $_session['user'] = $name;             header("location: user/");         }          else{             echo "<b>error</b>";         }     }     else{         echo "<b>error</b>";     } } 

you start session in login.php file. please remove @session_start(); users.php


Comments