Registration and Expiration Date in PHP and MySQL

Hey Technoz, In this tutorial we are going to learn how to create automatic registration and expiration date in php and mysql. Websites containing products required registration and expiration date. So database administrator can not handle huge amount of user’s  registration and expiration date. To make it reliable we can write the code so that we can easily create individual user’s expiration date in php and mysql can manage accordingly.

Creating database

A database need to be create to store the information about Registration and Expiration Date

So lets create the database by using following queries. The following SQL create expiration table which consist of  firstname, lastname, email, registerdate and expirationdate columns.

CREATE TABLE `expiration` (
  `firstname` varchar(50) NOT NULL,
  `lastname` varchar(50) NOT NULL,
  `mail` varchar(255) NOT NULL,
  `registerdate` text NOT NULL,
  `expirationdate` text NOT NULL
Dumping data for table ‘expiration’

Now lets insert some records by using following queries.

INSERT INTO `expiration` (`firstname`, `lastname`, `mail`, `registerdate`, `expirationdate`) VALUES
('Enrique ', 'Iglesias', '', '2018/07/26', '2019/07/26'),
('John', 'Cena', '', '2018/07/26', '2020/07/26'),
('Justin', 'Bieber', '', '2018/07/26', '2017/07/26');

First, To make it convenient, We will create a new PHP file for database configuration named dbconfig.php  that holds all configured parameters:

$con = mysqli_connect("localhost","root","","technopoints");

// Check connection
if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();


Registration and Expiration Date in PHP and MySQL

The following code index.php   is used to build user interface of Registration and Expiration Date in PHP and MySQL.

<!DOCTYPE html>
<html lang="en" >

<meta charset="UTF-8">
<title>Technopoints | Expiration</title>
<script src="" type="text/javascript"></script>
<link rel="stylesheet" href="css/index.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<link rel='stylesheet' href=''>
body {
    background: url("bgimg.jpeg");
	background-repeat: no-repeat;
	position: relative;
	background-attachment: fixed;
<script src=""></script>
  <div id="registration-form">
	<div class='fieldset'>
		<form action="" method="post" data-validate="parsley">
			<div class='row'>
			<!--	<label for='firstname'>First Name</label> -->
				<input type="text" placeholder="First Name" name='firstname' id='firstname' data-required="true" data-error-message="Your First Name is required" required>
			<div class='row'>
			<!--	<label for="lastname">Last Name</label> -->
				<input type="text" placeholder="Last Name"  name='lastname' data-required="true" data-type="email" data-error-message="Your Last Name is required" required>
			<div class='row'>
			<!--	<label for="email">Confirm your E-mail</label> -->
				<input type="text" placeholder="E-mail" name='email' data-required="true" data-error-message="Your E-mail must correspond" required>
			<input type="submit" value="Register" name="register">
  <script src=''></script>
<script src=''></script>

<?php   // this code is use to insert the form details and register and expiration date
include 'dbconfig.php';
$firstname = $_POST['firstname'];
$lastname  = $_POST['lastname'];
$email 	   = $_POST['email'];
$date      = date("Y/m/d");
$expdate   = date('Y/m/d', strtotime('+1 years'));
$fetch = "INSERT INTO `expiration`(`firstname`, `lastname`, `mail`, `registerdate`, `expirationdate`) VALUES ('$firstname','$lastname','$email','$date','$expdate')";
$fire = mysqli_query($con,$fetch);

<div class="container">
  <h2>Previous Entries</h2>
  <p>You can see registration date and expiration date of each user below:</p>            
  <table class="table table-hover">
      <tr class="info">
		<th>Registration Date</th>
        <th>Expiration Date</th>
$fetchqry = "SELECT * FROM `expiration`";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { ?>
        <td><?php echo $row['firstname'];?></td>
        <td><?php echo $row['lastname'];?></td>
		<td><?php echo $row['mail'];?></td>
        <td><?php echo $date1 = $row['registerdate'];?></td>
		<td><?php echo $date2 = $row['expirationdate'];?></td>
		<td><?php if(strtotime(date("Y/m/d")) < strtotime($date2)) echo "Active"; else { echo "Expired";} ?></td>
      </tr>											<?php } ?>
  1. First create a form so that user can able to register.
  2. Then take the user’s data by $_POST method and store it in the database by using SQL query.
  3. Fetch the current date by using date(“Y/m/d”) and store it as registration date.
  4. To add one year to the current date use date(‘Y/m/d’, strtotime(‘+1 years’)) store it as expiry date.
  5. Compare current date and expiry date using if(strtotime(date(“Y/m/d”)) < strtotime($date2)) if current date is lesser than expiry then status is active else expired.

Now, its time to do CSS of the above code to make User Interface looks pretty.


#registration-form {
  font-family:'Open Sans Condensed', sans-serif;
	width: 400px;
	margin: 20px auto;
	position: relative;

#registration-form .fieldset {

	border-radius: 3px;

 #registration-form legend {
	text-align: center;
	background: #364351;
	width: 100%;
	padding: 30px 0;
	border-radius: 3px 3px 0 0;
	color: white;

.fieldset form{
  border:1px solid #2f2f2f;
  margin:0 auto;
  padding:30px 20px;
  border-radius:0 0 3px 3px;
.placeholder #registration-form label {
	display: none;
 .no-placeholder #registration-form label{
  text-shadow:0 1px white;
/* all */
::-webkit-input-placeholder { text-shadow:1px 1px 1px white; font-weight:bold; }
::-moz-placeholder { text-shadow:0 1px 1px white; font-weight:bold; } /* firefox 19+ */
:-ms-input-placeholder { text-shadow:0 1px 1px white; font-weight:bold; } /* ie */
#registration-form input[type=text] {
	padding: 15px 20px;
	border-radius: 1px;
  margin:5px auto;
	border: 1px solid silver;

	-webkit-box-shadow: inset 0 1px 5px rgba(0,0,0,0.2);
	box-shadow: inset 0 1px 5px rgba(0,0,0,0.2), 0 1px rgba(255,255,255,.8);
	width: 100%;

	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	-ms-box-sizing: border-box;
	box-sizing: border-box;
  -webkit-transition:background-color .5s ease;
-moz-transition:background-color .5s ease;
-o-transition:background-color .5s ease;
-ms-transition:background-color .5s ease;
transition:background-color .5s ease;
.no-placeholder #registration-form input[type=text] {
	padding: 10px 20px;

#registration-form input[type=text]:active, .placeholder #registration-form input[type=text]:focus {
	outline: none;
	border-color: silver;

#registration-form input[type=submit] {
  font-family:'Open Sans Condensed', sans-serif;
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	-ms-box-sizing: border-box;
	box-sizing: border-box;
	width: 100%;
	background-color: #5C8CA7;
	padding: 10px;
	color: white;
	border: 1px solid #3498db;
	border-radius: 3px;
	font-size: 1.5em;
	font-weight: bold;
	margin-top: 5px;
	cursor: pointer;

#registration-form input[type=submit]:hover {
	background-color: #2980b9;

#registration-form input[type=submit]:active {

padding: 5px 11px;
margin: 0;
list-style: none;
border-radius: 0 0 3px 3px;
  border:1px solid #870d0d;
    -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  text-shadow:0px 1px 1px #460909;
#registration-form select{
::-moz-focus-inner {
  border: 0;

By using following form user can able to register and simultaneously registration and expiration date in php will run and dates will set in mysql.

The glimpse of the above code is in following snapshot.

Registration and Expiration Date in PHP and MySQL

After successfully register you can able to view the previous entries. As well as can able to view whether the current status is active or Expired.

Registration and Expiration Date in PHP and MySQL

In this tutorial we have learn how to create automatic registration and expiration date in php and mysql.

If you have any doubts regarding to this tutorial feel free to ask in the comment section below.

To catch even more knowledgeable and easy understandable tutorials please subscribe to get email notification.

Download Source Code

3 thoughts on “Registration and Expiration Date in PHP and MySQL

  1. A
    Arshpreet kaur says:

    $content .=”;
    $content .=’Issue Date’;
    $content .=’Return Date’;
    $content .=’status’;
    $content .=”;
    $VRF_results=$wpdb->get_results(“SELECT * FROM $table_name”);
    foreach($VRF_results as $VRF_rows){
    $issue = $VRF_rows->issue_date;
    $days = $VRF_rows->days;
    $content .=”
    . ucwords($issue).
    $content .=”
    $content .=”;
    if(strtotime($issue) < strtotime($return))
    $content.= "Active";
    else {

    $content.= "Expired";


    I am using your code for showing status , only active is showing. what is reason ?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.