Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8398879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:09:28+00:00 2026-06-09T21:09:28+00:00

So for a project I’m working on, it is necessary to login by simply

  • 0

So for a project I’m working on, it is necessary to login by simply filling out an option on a dropdown menu and then clicking submit (no password field).

Any search I do on the topic returns info about making those neat dropdown menus akin to that of twitter. And when I attempted this myself a great abomination of a server error occurred.

<?php

mysql_connect("localhost", "root", "mypassword")or die("cannot connect"); 
mysql_select_db("lunch_punch")or die("cannot select DB");

$myname=$_POST['myname'];


session_register("myname");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}

<?php
session_start();
if(!session_is_registered(myname)){
header("location:home.html");
}
?>

<html>
<body>
Login Successful
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:09:30+00:00Added an answer on June 9, 2026 at 9:09 pm

    Here ive put together this example/tut as I suspect your looking at a really old tutorial;

    Its very simple to follow and covers alot of aspects including safely connecting to a database using PDO and querying it, session control, and the use of a simple class and accessing its methods. Hope it helps.

    <?php 
    session_start();
    
    class simpleLogin{
        public $error;
    
        function __construct($dsn, $user=null, $pass=null){
            $this->dsn = $dsn;
            $this->user = $user;
            $this->pass = $pass;
            //Connect
            $this->connect();
        }
    
        function connect(){
            try{
                $this->db = new PDO($this->dsn, $this->user, $this->pass);
                $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
                $this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
            }catch (Exception $e){
                die('Cannot connect to databse. Details:'.$e->getMessage());
            }
        }
    
        //Get all users from db for drop down box
        function get_all_users(){
            $sql = "SELECT * FROM users";
            $statement = $this->db->query($sql);
            $statement->execute();
            return $statement->fetchAll();
        }
    
        /**
         * The main check_login method, this method is called
         *  on each page load to check status of logged in user
         *  or handle form POST login.
         *
         * @return bool
         */
        function check_login(){
            //Logout
            if(isset($_GET['logout'])){$this->logout();}
    
            //Already Logged in
            if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']===true){return true;}
    
            //User posted login form
            if($_SERVER['REQUEST_METHOD']=='POST'){
                if(!empty($_POST['myname'])){
                    /*
                    CREATE  TABLE `lunch_punch`.`users` (
                    `id` INT NOT NULL AUTO_INCREMENT ,
                    `username` VARCHAR(255) NULL ,
                    PRIMARY KEY (`id`) );
                    */
                    $sql = "SELECT 1 FROM users WHERE username=:username";
                    $statement = $this->db->prepare($sql);
                    $statement->bindParam(':username', $_POST['myname']);
                    $statement->execute();
                    $result = $statement->fetch();
                    if(!empty($result)){
                        $_SESSION['logged_in']=true;
                        return true;
                    }else{
                        return false;
                    }
                }else{
                    $this->error = 'Please select your name!';
                }
            }
        }
    
        /**
         * Logout user and then redirect to index
         *
         */
        function logout(){
            session_destroy();
            session_regenerate_id(true);
            exit(header('Location: index.php'));
        }
    }
    
    
    //Start the login class and pass your mysql connection details
    $login = new simpleLogin('mysql:host=127.0.0.1;dbname=lunch_punch','root','password');
    
    //Check the login
    if($login->check_login() === true){
        //Logged In, wOOt do whatever...
        echo 'You are logged in... <a href="?logout">Logout</a>';
    }else{
        //Logged Out, show login form
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Simple Login by Select Box</title>
    </head>
    <form method="POST" action="">
      <p>Please Login by selecting your name.</p>
    
      <p><select size="1" name="myname">
          <option value="" selected>-- Select Your Name --</option>
          <?php 
          //Get all users from database and output into the option box
          foreach($login->get_all_users() as $user):?>
          <option value="<?php echo $user['username'];?>"><?php echo $user['username'];?></option>';
          <?php endforeach;?>
         </select>
         <input type="submit" value="Login">
      </p>
      <?php echo ((!empty($login->error))?'<span style="color:red;">'.$login->error.'</span>':null);?>
    </form>
    <body>
    </body>
    </html>
    <?php } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The project that I am working on (Node.js) implies lots of operations with the
Project was running fine, i made a change some where and couldn't figure out
Project I'm working on uses jQuery. I have a series of Ajax calls being
Project Euler 126 says: If we then add a second layer to this solid
Project file here if you want to download: http://files.me.com/knyck2/918odc So I am working on
Current project is an Mvc4 application, I had Ioc working and recently it just
The project i am working at right now requires some declarative way of defining
A project I am working on only builds with maven-2.2: for earlier versions, the
A project I am working on, we have decided to implement ehcache for our
The project was working fine with Django 1.3, once I updated to 1.4 results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.