Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my web application codes for a registration form( login codes, error codes, index codes and server codes for my web application) When i

This is my web application codes for a registration form( login codes, error codes, index codes and server codes for my web application)

When i log in with already registered details, it doesnt open to the next page(logged in successfully)

I will be very happy if you identify the error for me

Use this codes and identify the error for me to login with already registered details

Nb: moreover, write a nice designed css code for this codes for nice presentation


REGISTRATION.PHP

Registration System


REGISTER



 

First Name










   






Already have account? Log In


LOGIN.PHP


Registration system


LOG IN




Not a user? Register Here


ERROR.PHP

0) : ?>



SERVER.PHP


session_start();


// initializing variables

$First_name = "";

$Last_name = "";

$Email    = "";

$School_ID    = "";

$PIN    = "";

$msg = "";

$errors = array(); 


// connect to the database

$db = mysqli_connect('localhost', 'root', '', 'student') or die('Could not connect to database');



//If tthe register button is clicked 

if (isset ($_POST ['reg_student'])){


  // REGISTER student

  // receive all input values from the form

  $First_name = mysqli_real_escape_string($db, $_POST['First_name']);

  $Last_name = mysqli_real_escape_string($db, $_POST['Last_name']);

  $Email = mysqli_real_escape_string($db, $_POST['Email']);

  $School_ID = mysqli_real_escape_string($db, $_POST['School_ID']);

  $PIN_1 = mysqli_real_escape_string($db, $_POST['PIN_1']);

  $PIN_2 = mysqli_real_escape_string($db, $_POST['PIN_2']);



  // form validation: ensure that the form is correctly filled ...

  // by adding (array_push()) corresponding error unto $errors array

  if (empty($First_name)) {

    array_push($errors, "First name is required");

  }

  if (empty($Last_name)) {

    array_push($errors, "Last Name is required");

  }

  if (empty($School_ID)) {

    array_push($errors, "School ID is required");

  }

  if (empty($PIN_1)) {

    array_push($errors, "PIN is required");

  }

  if ($PIN_1 != $PIN_2){

    array_push($errors, "PIN do not match");

  }


  


  // first check the database to make sure 

  // a student does not already exist with the same school ID and/or email and/or pin

  $registration_form_check_query = "SELECT * FROM registration_form  WHERE School_ID='$School_ID' OR Email='$Email' OR PIN='$PIN' LIMIT 1";

  $results = mysqli_query ($db, $registration_form_check_query);

  $registration_form = mysqli_fetch_assoc($results);

  

  if ($registration_form) { // if student exists

    if ($registration_form ['School_ID'] === $School_ID) {

      array_push($errors, "School ID already exists");

    }


    if ($registration_form ['Email'] === $Email) {

      array_push($errors, "Email already exists");

    }

        

        if ($registration_form ['PIN'] === $PIN) {

      array_push($errors, "PIN already exists");

    }

        

  }


  // Finally, register student if there are no errors in the form

  if (count($errors) == 0) {

        $PIN = md5($PIN_1); //This will encrypt the pin

        $sql = "INSERT INTO registration_form (First_name, last_name, Email, School_ID, PIN) 

                          VALUES('$First_name', '$Last_name', '$Email', '$School_ID', '$PIN')";


      $sql =mysqli_query($db, $sql);


        

        if ($sql) {

                $msg = "Registration successfully completed";

        

        header('location: index.php');

  }

  


}

// USER LOGIN


if(isset($_POST['Login_user'])){

  $School_ID = mysql_real_escape_string($db, $_POST['School_ID']);

  $PIN= mysql_real_escape_string($db, $_POST['PIN']);


if(empty($School_ID)){



  array_push($errors, "School ID is required");

}

if(empty($PIN)){



array_push($errors, "PIN is required");

}


if(count($errors) == 0){


  $PIN = mds($PIN);


  $sql = "SELECT * FROM registration_form WHERE School_ID = '$School_ID' AND PIN = '$PIN' ";


$results = mysql_query($db, $sql);


if(mysqli_num_rows($results)){


  $_SESSION['School_ID'] = $School_ID;


$_SESSION['SUCCESS'] = "LOGGED IN SUCCESSFULLY";


header('location: index.php');


}


else{

  array_push($errors, "WRONG School_ID/ PIN. PLEASE TRY AGAIN.");

}

}

}



INDEX.PHP


session_start();

if(isset($_SESSION['School_ID'])){

$_SESSION['msg'] = "You must log in first to view this page ";

header("location : login.php");

}

if(isset($_GET['Logout'])){

session_destroy();

unset($_SESSION['School_ID']);

header("location : login.php");

}

?>




<b>HOME PAGE</b>




This is the homepage



if(isset($_SESSION['success'])) : ?>







echo $_SESSION['success'];

unset($_SESSION['success']);

?>







If the user logs in, print information about him



Welcome






 }

Step by Step Solution

3.42 Rating (165 Votes )

There are 3 Steps involved in it

Step: 1

tablesql CREATE DATABASE student use student CREATE TABLE registrationform id INT11 NOT NULL AUTOINCREMENT Firstname varchar255 NOT NULL Lastname varc... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Legal Environment of Business

Authors: Roger E Meiners, Al H. Ringleb, Frances L. Edwards

11th Edition

9781133419716, 538473991, 1133419712, 978-0538473996

More Books

Students also viewed these Programming questions

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago