0% found this document useful (0 votes)
81 views9 pages

PHP MySQL User Registration System

The document describes an assignment to create a user registration system using PHP and MySQL. It includes screenshots and code for the registration page, login page, database connection file, authentication session file, and login success page. The registration page allows users to enter their username, email, and password. If registration is successful, it redirects to the login page. The login page checks submitted credentials against the database and redirects to the success page upon valid login. The provided code contains PHP scripts and CSS for connecting to the database and building the registration, login, and profile pages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views9 pages

PHP MySQL User Registration System

The document describes an assignment to create a user registration system using PHP and MySQL. It includes screenshots and code for the registration page, login page, database connection file, authentication session file, and login success page. The registration page allows users to enter their username, email, and password. If registration is successful, it redirects to the login page. The login page checks submitted credentials against the database and redirects to the success page upon valid login. The provided code contains PHP scripts and CSS for connecting to the database and building the registration, login, and profile pages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

G. H. RAISONI COLLEGE OF ENGG.

, NAGPUR
(An Autonomous Institute under UGC Act 1956)
Department of Computer Science & Engg.

Date: 03/07/2021

Skill Course: PHP


Session: 2021-22

Student Details:
Roll Number 40
Name Priyanka Singh
Semester 7
Section C

Assignment 2- Day 3

Q. Create a user registration system using PHP and MySQL database as per the
attached format.

MySQL Workbench Screenshots:


db.php

<?php
$con = mysqli_connect("localhost","root","","php_skillcourse");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>

auth_session.php

<?php
session_start(); if(!
isset($_SESSION["username"])) {
header("Location: login.php");
exit();
}
?>

Registration Page Screenshot:


registration.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Registration</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<?php
require('db.php');
// When form submitted, insert values into the database.
if (isset($_REQUEST['username'])) {
// removes backslashes
$username = stripslashes($_REQUEST['username']);
//escapes special characters in a string
$username = mysqli_real_escape_string($con, $username);
$email = stripslashes($_REQUEST['email']);
$email = mysqli_real_escape_string($con, $email);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con, $password);
$create_datetime = date("Y-m-d H:i:s");
$query = "INSERT into `users` (username, password, email, create_datet
ime)
VALUES ('$username', '" . md5($password) . "', '$email', '$c
reate_datetime')";
$result = mysqli_query($con, $query);
if ($result) {
echo "<div class='form'>
<h3>You are registered successfully.</h3><br/>
<p class='link'>Click here to <a href='login.php'>Login</a></p>
</div>";
} else {
echo "<div class='form'>
<h3>Required fields are missing.</h3><br/>
<p class='link'>Click here to <a href='registration.php'>regist
ration</a> again.</p>
</div>";
}
} else {
?>
<form class="form" action="" method="post">
<h1 class="login-title">Registration</h1>
<input type="text" class="login-
input" name="username" placeholder="Username" required />
<input type="text" class="login-
input" name="email" placeholder="Email Adress">
<input type="password" class="login-
input" name="password" placeholder="Password">
<input type="submit" name="submit" value="Register" class="login-button">
<p class="link"><a href="login.php">Click to Login</a></p>
</form>
<?php
}
?>
</body>
</html>

Login Page Screenshot:


login.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Login</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<?php
require('db.php');
session_start();
// When form submitted, check and create user session.
if (isset($_POST['username'])) {
$username = stripslashes($_REQUEST['username']); // removes backslashe
s
$username = mysqli_real_escape_string($con, $username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con, $password);
// Check user is exist in the database
$query = "SELECT * FROM `users` WHERE username='$username'
AND password='" . md5($password) . "'";
$result = mysqli_query($con, $query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if ($rows == 1) {
$_SESSION['username'] = $username;
// Redirect to user Success page
header("Location: success.php");
} else {
echo "<div class='form'>
<h3>Incorrect Username/password.</h3><br/>
<p class='link'>Click here to <a href='login.php'>Login</a> aga
in.</p>
</div>";
}
} else {
?>
<form class="form" method="post" name="login">
<h1 class="login-title">Login</h1>
<input type="text" class="login-
input" name="username" placeholder="Username" autofocus="true"/>
<input type="password" class="login-
input" name="password" placeholder="Password"/>
<input type="submit" value="Login" name="submit" class="login-button"/>
<p class="link"><a href="registration.php">New Registration</a></p>
</form>
<?php
}
?>
</body>
</html>
Login Success Screenshot:

success.php

<?php
//include auth_session.php file on all user panel pages
include("auth_session.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dashboard - Client area</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="form">
<p>Hey, <?php echo $_SESSION['username']; ?>!</p>
<p>You are now successfully logged in.</p>
<p><a href="logout.php">Logout</a></p>
</div>
</body>
</html>

logout.php

<?php
session_start();
// Destroy session
if(session_destroy()) {
// Redirecting To Home Page
header("Location: login.php");
}
?>

Logout redirects user back to home/login page.

style.css(for all pages)

body {
background: #3e4144;
}
.form {
margin: 50px auto;
width: 300px;
padding: 30px 25px;
background: white;
}
h1.login-title {
color: #666;
margin: 0px auto 25px;
font-size: 25px;
font-weight: 300;
text-align: center;
}
.login-input {
font-size: 15px;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 25px;
height: 25px;
width: calc(100% - 23px);
}
.login-input:focus {
border-color:#6e8095;
outline: none;
}
.login-button {
color: #fff;
background: #55a1ff;
border: 0;
outline: 0;
width: 100%;
height: 50px;
font-size:
16px;
text-align: center;
cursor: pointer;
}
.link {
color: #666;
font-size:
15px;
text-align: center;
margin-bottom: 0px;
}
.link a {
color: #666;
}
h3 {
font-weight: normal; text-align: center;
}

You might also like