<?php include_once 'functions.php'; $db = (require_once __DIR__ . '/../config/db.php'); session_start(); if (!all_params($_POST)) { return header("location: login.php"); } $connection = mysqli_connect($db['host'], $db['username'], $db['password'], $db['database']); $email = $_POST['email']; $find_user_sql = "select id, password, type_id from users where email = '{$email}'"; $result = mysqli_query($connection, $find_user_sql); if (mysqli_num_rows($result) > 0) { // since email is unique, we don't need to loop. There is only 1 result set $row = mysqli_fetch_assoc($result); if (password_verify($_POST['password'], $row['password'])) { switch ($row['type_id']) { case 1: // admin $find_admin_sql = "select id, username from admins where user_id = " . $row['id']; $admins = mysqli_query($connection, $find_admin_sql); $admin_row = mysqli_fetch_assoc($admins); $_SESSION['local_id'] = $admin_row['id']; $_SESSION['user_handle'] = $admin_row['username']; break; case 2: //student $find_student_sql = "select id, first_name, last_name from students where user_id = " . $row['id']; $students = mysqli_query($connection, $find_student_sql); $student_row = mysqli_fetch_assoc($students); // only one result set
<?php include_once 'functions.php'; $db = (require_once __DIR__ . '/../config/db.php'); session_start(); // if he user is already logged in, redirect them on the index page if (isset($_SESSION['id'])) { return header("location: /"); } // sign the new user up and redirect him to index. if (all_params($_POST)) { // print_r($_POST); $connection = mysqli_connect($db['host'], $db['username'], $db['password'], $db['database']); if (!$connection) { die('Can\'t connect to the database: ' . mysqli_connect_errno()); } $result = store_new_student($connection, $_POST); mysqli_close($connection); if ($result == -1) { return header("location: signup.php"); } else { $_SESSION['id'] = $result['user_id']; $_SESSION['type_id'] = 2; // student $_SESSION['local_id'] = $result['student_id']; $_SESSION['user_handle'] = $result['student_handle']; return header("location: /"); } } else { return header("location: signup.php"); }