PHP User::set_uid Examples

PHP User::set_uid - 2 examples found. These are the top rated real world PHP examples of User::set_uid extracted from open source projects. You can rate examples to help us improve the quality of examples.
 //Grab password to verify it. Also grab idUsers, first name, last name and UID to use later
 $query = "SELECT password, idUsers, first_name, last_name, uID FROM Users WHERE username = :username";
 $stmt = $dbh->prepare($query);
 $stmt->bindParam(':username', $_POST['username'], PDO::PARAM_STR);
 //If the username exists, check the password
 if ($stmt->rowCount() > 0) {
     $result = $stmt->fetch();
     $dbPassword = $result['password'];
     if ($dbPassword == hash('sha256', $_POST['password'])) {
         //Now that the user is good to log in, unset all session variables except requestedPage
         //Then populate the user object
         $user = new User();
         //Store the user's UID in a session variable for easy access
         $_SESSION['uid'] = $result['uID'];
         //Now assign the user their roles
         $query = "SELECT role FROM Roles WHERE idUsers = :idUser";
         $stmt = $dbh->prepare($query);
         $stmt->bindParam(':idUser', intval($result['idUsers']), PDO::PARAM_INT);
         $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
         //Now add the user's roles to the User object
         foreach ($result as $row) {
             echo "I'm adding this: " . $row['role'];
     * Next, we'll need to find the TAs that have requested to TA for this course this semester and year
    $query = "SELECT DISTINCT U.uID, U.first_name, U.last_name, TA.class_request, TA.recommend\n              FROM Users U, TA_Applicants TA\n              WHERE U.uID = TA.uID AND TA.class_request = :catNum AND semester = :semester AND year = :year\n              ORDER BY TA.recommend DESC";
    $stmt = $dbh->prepare($query);
    $stmt->bindValue(':catNum', $courseNum, PDO::PARAM_INT);
    $stmt->bindValue(':semester', $semester, PDO::PARAM_STR);
    $stmt->bindValue(':year', $year, PDO::PARAM_INT);
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
    //Create an array to hold all of the User objects
    $taArray = [];
    foreach ($result as $row) {
        //Create a new user object
        $currentUser = new User();
        //Set the available variables
        //Add the object to correct array
        $taArray[] = $currentUser;
    $dbh = null;
} catch (PDOException $e) {
    print "Error!:" . $e->getMessage() . "<br/>";
 * Now that all of the information has been gathered from the database, we can use it to generate some html.