Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pesase explain, shouw your source code and the output. I am trying this about a week but it don't work. Can someone help please? I

Pesase explain, shouw your source code and the output.

I am trying this about a week but it don't work. Can someone help please? I provided my code for login.php, register.php, database.php, logout.php files and output image of my login. php image. As seen below my login form throwing errors as seen below. My register page is working but it don't enter first name and last to mySQL database, it enters only user name and passord.

I am using XAMPP 7.2.11-0 on my mac.

The error am getting from login form submited

image text in transcribed

//login.php

session_start();

if( isset($_SESSION['user_id']) ){ header("Location: /"); }

require 'database.php';

if(!empty($_POST['email']) && !empty($_POST['password'])): $records = $conn->prepare('SELECT id,email,password FROM administrator WHERE email = :email'); $records->bindParam(':email', $_POST['email']); $records->execute(); $results = $records->fetch(PDO::FETCH_ASSOC);

$message = '';

if(count($results) > 0 && password_verify($_POST['password'], $results['password']) ){

$_SESSION['user_id'] = $results['id']; header("Location: /");

} else { $message = 'Sorry, those credentials do not match'; }

endif;

?>

Login Below

To main page

if(!empty($message)): ?>

?> or Register here

Login to CSIT website

Please Login Here

Email:
Password:
Loing

You must login to view this site.

register.php

session_start();

if( isset($_SESSION['user_id']) ){ header("Location: /"); }

//require 'database.php';

$message = '';

$server = 'localhost'; $username = 'root'; $password = ''; $database = 'csit101';

try{ $conn = new PDO("mysql:host=$server; dbname=$database;", $username, $password); } catch(PDOException $e){ die( "Connection failed: " . $e->getMessage()); }

if(!empty($_POST['email']) && !empty($_POST['password'])): // Enter the new user in the database $sql = "INSERT INTO administrators (email, password) VALUES (:email, :password)"; $stmt = $conn->prepare($sql);

$stmt->bindParam(':email', $_POST['email']); $pass = ':password'; $phash = password_hash($_POST['password'], PASSWORD_BCRYPT);

$stmt->bindParam($pass, $phash); //$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));

if( $stmt->execute() ): $message = 'Successfully created new user'; else: $message = 'Sorry there must have been an issue creating your account'; endif;

endif;

?>

Register Below

To main page

or Login here

Register to CSIT website

Please Register Here.

First Name:
Last Name:
Email Address:
Password:

Register

You must register to view this site.

database.php

$server = 'localhost'; $username = 'root'; $password = ''; $database = 'csit101';

try{ $conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password); } catch(PDOException $e){ die( "Connection failed: " . $e->getMessage()); }

logout.php

session_start();

session_unset();

session_destroy();

header("Location: /");

image text in transcribed

image text in transcribedimage text in transcribed

Warning: countO: Parameter must be an array or an object that implements Countable in /Applications/XAMPP/xamppfiles/htdocs/Login and Registration/login.php on line 20 To main page Sorry, those credentials do not match or Register here Login to CSIT website Please Login Here Email:Enter your emai Password: and password Loing You must login to view this site

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions