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 9152759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:08:00+00:00 2026-06-17T12:08:00+00:00

Im trying to understand how to build a user registration with PHP and MySQL.

  • 0

Im trying to understand how to build a user registration with PHP and MySQL.

I have built a form that the user can fill out and the information is then stored in my table.

error_reporting(E_ALL);
include_once ('connection.php');

// Required field names
$required = array('firstname', 'lastname', 'email', 'password', 'accounttype');

// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) {
  if (empty($_POST[$field])) {
    $error = true;
  }
}

if ($error) {
  echo "All fields are required.";
} else {
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $password = md5($_POST['password']);
    $accounttype = $_POST['accounttype'];

    $query = "INSERT INTO users(firstname,lastname,email,password,accounttype) VALUES (:firstname,:lastname,:email,:password,:accounttype)";
      $stmt = $dbh->prepare($query);
      $stmt->bindParam(':firstname', $firstname);
      $stmt->bindParam(':lastname', $lastname);
      $stmt->bindParam(':email', $email);
      $stmt->bindParam(':password', $password);
      $stmt->bindParam(':accounttype', $accounttype);
      $stmt->execute();

    if(!$query){
        echo 'Whoops, something went wrong!';
    } else {
        echo $accounttype;
        if($accounttype == '1'){
            header ('Location: /england/dashboard.php');
            exit;
        }; 
        if($accounttype == '2'){            
            header ('Location: /ireland/dashboard.php');
            exit;
        };
    };
};

When the users completes the form they’re either reidrected to a different page based on their account type.

On those pages I need to somehow check to see if the user is of accounttype ‘X’. So if they land in

header ('Location: /ireland/dashboard.php');

their account type value will be equal to 2, so only people with an account type of 2 can visit the above mentioned.

I’ve read about session variables, but where do I set these?

  • 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-17T12:08:02+00:00Added an answer on June 17, 2026 at 12:08 pm
     session_start(); // this at top of page
     if($accounttype == '1'){
            $_SESSION['accountType'] = 1; // or $accounttype
            header ('Location: /england/dashboard.php');
            exit();
        }; 
        if($accounttype == '2'){ 
            $_SESSION['accountType'] = 2; // or $accounttype         
            header ('Location: /ireland/dashboard.php');
            exit();
        };
    

    In england/dashboard.php

    session_start();
    if($_SESSION['accountType'] !== 1) header('location: login.php');
    

    In ireland/dashboard.php

    session_start();    
    if($_SESSION['accountType'] !== 2) header('location: login.php');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to build a WPF single user application that needs to handle images
I have a small email application that lets a user build a message from
I'm trying to understand how to build a JSON object in JavaScript. This JSON
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand the Deezer API. When I visit: http://connect.deezer.com/oauth/auth.php?app_id=MY_APP_ID&redirect_uri=http://mydomain.me&perms=basic_access I end up at
I am trying to build a db driven web site in which the user
I am trying to build my own user authentication system (simply because the ones
I'm trying to gradually build up an image based on user inputs. What I'm
I have a simple user factory that looks like this: FactoryGirl.define do factory :user
I'm trying to build a fairly complex form which as a couple of cascading

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.