Android ImageButton -- can't get image in the center

117

Solution 1

I'm a real moron. That's how it appears in the display the Ecliplse plugin provide side-by-side with the XML editor. When I actually build the project and ran it on a device, it displayed everything correctly.

Solution 2

Ironically I had exactly the opposite problem with an ImageView - I couldn't get it left-aligned no matter what I tried. In this case I was using layout_width="fill_parent".

See my question here: Android layout - alignment issue with ImageView

Share:
117
papadammy
Author by

papadammy

Updated on August 03, 2022

Comments

  • papadammy
    papadammy almost 2 years

    Good day house. This is the second time I got locked out of the web application I am working on. It's still being developed on my localhost (laptop) using PHP and MySQL. Please what could be responsible for this? I have been on the project for some months now but got locked out now within the space of 2 weeks. No new plugin or third party stuff. What exactly could be responsible for this? The only thing that has changed is my PHP version(the previous and current is still PHP7, just a minor upgrade). What should I look out for?

    I have few other users who can log in and few who can't just like me, so the problem is not with the login code. I have been login in and out before being shut out suddenly with no apparent reason while others can still login. It's not a code problem I guess.

    Here is my login code

    require_once '../classes/DbManager.php';
    
    $error = array();
    
    if (isset($_POST['action']) && $_POST['action'] == 'login') 
    {
       //Validate/Sanitize the user input
       $username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
       $password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
       
       if(empty($username))
       {
           $error[] = 'The username field cannot be left empty';
       }
       
       if(empty($password))
       {
           $error[] = 'The password field cannot be left empty';
       }
       
       if(empty($error))
       {
          // start the session
          session_start(); 
          
            // connect to the database
            $conn = DbManager::getConnection();
            //Get the hash from the database
            try{
            $sql = "SELECT hash FROM users WHERE username = :username";
    
            $st = $conn->prepare($sql);
            // bind variables when executing statement
            $st->bindValue(':username', $username);
            $st->execute();
            }
            catch (PDOException $e)
            {
            $error[] = 'Invalid username or password.';
            }
            // if a match is found, rowCount() produces 1, which is treated as true
            
           if($st->rowCount() == 1) 
            { 
                $row = $st->fetch();
                $hash = $row['hash'];
            }
            
            // connect to the database
            $conn = DbManager::getConnection();
            //Now connect to log the user in
            try{
            $sql = "SELECT username FROM users WHERE username = :username AND password = AES_ENCRYPT(:password, :hash)";
    
            $stmt = $conn->prepare($sql);
            // bind variables when executing statement
            $stmt->bindValue(':username', $username);
            $stmt->bindValue(':password', $password);
            $stmt->bindValue(':hash', $hash);
            $stmt->execute();
            }
            catch (PDOException $e)
            {
            $error[] = 'Invalid username or password.';
            }
            // if a match is found, rowCount() produces 1, which is treated as true
            
            
           if($stmt->rowCount() == 1) 
            { 
                $row = $stmt->fetch();
                $username = $row['username'];
               
            $_SESSION['loggedIn'] = TRUE;
            $_SESSION['username'] = $username;
            
            session_regenerate_id(true);
            }
    
            // if no match, destroy the session and prepare error message
            else {
            $_SESSION = array();
            session_destroy();
            $error[] = 'Invalid username or password.';
            }
            
            
            // if the session variable has been set, redirect
            if (isset($_SESSION['loggedIn'])) {
            // get the time the session started
            $_SESSION['start'] = time();
    
            $login = TRUE;
    
            header('Location: ../my-account/');
            exit();
            }
            else
            {
        header('Location: .');
        }
       }
       
    }