0

I tried to create a login script using some functions but session not work

this is my code

if(isset($_POST['submit'])){
  $username = $_POST["username"];
  $password = md5($_POST["password"]);

  if(login($username, $password)){
    $_SESSION['id'] == $row['ID'];
    redirect_to('index.php');
    exit();
  }
}

And i create this function named login

function login($user, $pass) {

    // Sanitize user input
    $user = strtolower(sanitize_input($user));
    $pass = sanitize_input($pass);

    // Build database query
    $sql = "select * from users where username = '".$user."' and password = '".$pass."' limit 1";
    $row = execute_query($sql);
    if($user == strtolower($row['username']) && $pass == $row['password']){
      return true;
    }else{
      return false;
    }
}

And this is another function named execut_query

function execute_query($sql) {

    // Initialize dataset
    $dataset = FALSE;

    // Execute database query
    $result = @execute_statement($sql);

    // Count number of rows
    $count = @mysql_num_rows($result);

    // Check for single row returned
    if ($count == 1) {

        // Fetch a single row from database cursor
        $dataset = @mysql_fetch_assoc($result);
    }

    // Check for multiple rows returned
    if ($count > 1) {

        // Initialize rows array
        $dataset = array();

        // Fetch all rows from database cursor
        while ($row = @mysql_fetch_assoc($result)) {
            $dataset[] = $row;
        }
    }

    // Return dataset
    return $dataset;
}

Whene i press submit login form session not set

Web Stair
  • 120
  • 1
  • 2
  • 15

0 Answers0