PLC BLOG | SIGNUP LOGIN PAGE IN PHP WITH DATABASE (MYSQL)

Warning: include(../../socialplugin1.php): Failed to open stream: No such file or directory in /home/u658851932/domains/plcblog.in/public_html/socialplugin.php on line 1

Warning: include(): Failed opening '../../socialplugin1.php' for inclusion (include_path='.:/opt/alt/php82/usr/share/pear:/opt/alt/php82/usr/share/php:/usr/share/pear:/usr/share/php') in /home/u658851932/domains/plcblog.in/public_html/socialplugin.php on line 1
lg-12 col-12 fb-share-button">

Share on Facebook

Share on twitter

Share on Whats-App

user registration is most important for website, it helps to manage the record and valuable information of about your visitors/page memebers. complete user registration and signin form in php. In this article, You know how to make a registration form with complete validation like email, mobile.Welcome.Php: When A Visitors Open Your Page I.E. Welcome.Php, If Visitor Are Not Login So Page Redirect To Login Page. If Visitors Dont Have Account On This Website So There Is Register Or Sign Up Option Availble On Sign In Page. After Successfully Registration Or Sign In User Are Access Your Welcome Page. This Is A Very Simple Page With Little Style. You Can Manage As You Want. For Download Complete Source Link Below.

Create A user Register Form

register.php

make a simple user registration form where user enter their details like name, email, mobile no etc. i am using method post.


code for register.php

<form action ="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"; method="POST">

<div class="form_div">
<div class="header_register">
<p>SignUP</p>
<?php include_once('action_register.php'); ?>
<hr>
<p style="text-decoration: none;font-size: 20px;">Already Member
<a href="login.php" style="text-decoration: none;font-size: 20px; 
color: white;"> <u>SIGN IN</u></a></p> 
</div>
	<label for="name">Name</label>
	<input  type="text" class="" name="name" placeholder="Enter Your Name:">
	<hr class="hr_style">
	
<label for="email">Email</label>
	 <input type="email" name="email" placeholder="Enter Your email">
  <hr class="hr_style">
  
	 <label for="password">Password</label>
	<input type="password" name="password" placeholder="Enter password">
  <hr class="hr_style">
  
	<label for="mobile">Mobile</label>
   <input type="number" id="mobile" name="mobile" placeholder="10 digit mobile no">
   <hr class="hr_footer">
   
   <div class="header_register">
  
 <button class="submit_button" name="SIGNUP"  >SIGN UP</button>
 
</div></div> </form>

css style


<style>
input{
width: 70%;padding: 8px 10px;margin-left: 60px;box-sizing: border-box;
display: block; border: 1px solid grey;
border-radius: 6px;font-size: 15px; align-content: center;}

.form_div{
width: 28%;background-color:
 white;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 
border: 2px solid #6749b6;margin-left: 450px;margin-top: 50px;	}

.form_div label{color:black;font-size: 20px;width: 30%;margin-left: 60px;}

.header_register 
{ background-color: #6749b6;color: white;text-align: center;
font-size: 30px;margin-top: 0px;padding: 10px 20px;}

.hr_style{width: 70%;border:1px solid transparent;}

.submit_button{padding: 10px 20px;background-color: #f2f2f2;border: 1px solid #f2f2f2;font-size: 20px;}
</style>
		

Create A mysql database

CREATE TABLE `user_register` (
  `id` int(200) NOT NULL,
  `name` varchar(1000) NOT NULL,
  `email` varchar(1000) NOT NULL,
  `password` longtext NOT NULL,
  `mobile` bigint(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

sign in form

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">

<div class="form_div">
<div class="header_register">
<p>SignUP</p>
<?php 
include_once('action_register.php');
?>	
<hr>
<p style="text-decoration: none;font-size: 20px;">Become Member<a href="register.php" style="text-decoration: none;font-size: 20px; color: white;"> <u>Register</u></a></p> 
</div>
	<label for="name">Email</label>
	 <input type="email" name="email" placeholder="Enter Your email">
  <hr class="hr_style">
	 <label for="name">Password</label>
	<input type="password" name="password" placeholder="Enter password">
  <hr class="hr_style">
   <hr class="hr_footer">
   <div class="header_register">
 <button class="submit_button" name="login"  >Login</button>
</div>   </div></form>
	

code/index.php

		<div class="form_div">
<div class="header_register">
<p>SignUP</p>
<?php 
include_once('action_register.php');
?>	
<hr>
<?php  if (isset($_SESSION['email'])) : ?>

<p style="text-decoration: none;font-size: 20px;">WELCOME <br><a  href="?logout" style="text-decoration: none;font-size: 20px; color: white;"> <u>Log Out</u></a>
<br>
<p><?php echo "Email:-".  $_SESSION['email']; ?></p></p> 

</div>   </div>
 <?php endif ?>
 <?php  if (!isset($_SESSION['email'])) : ?>
 <?php 
header('location: login.php');
?>       
 <?php endif ?>

	

action_register.php

	
<?php
session_start();
$errors = array(); 
$db = mysqli_connect('localhost', 'root', 'password', 'database name');
		$classname="errors";
			 if (isset($_POST['SIGNUP'])) {
		// receive all input values from the form
		$email = mysqli_real_escape_string($db, $_POST['email']);
		$name = mysqli_real_escape_string($db, $_POST['name']);
		$password = mysqli_real_escape_string($db, $_POST['password']);
			$mobile = mysqli_real_escape_string($db, $_POST['mobile']);

		// form validation: ensure that the form is correctly filled
		if (empty($name)) { array_push($errors, " name is required"); }
		if (empty($email)) { array_push($errors, " Email is required"); }
		if (empty($password)) { array_push($errors, " enter valid password"); }
		if (empty($mobile)) { array_push($errors, " mobile No. is required"); }
		
		if(strlen($mobile)==10){}	else
{array_push($errors, "enter 10 digit mobile");}		

$record_check = "SELECT * FROM user_register";
$result_check = $db -> query($record_check);
 	$email_check=$mobile_check="";
 if ($result_check->num_rows > 0) {
  // output data of each row
  while($row = $result_check->fetch_assoc()) {
$email_check=  $row['email'];
$mobile_check=  $row['mobile'];
$password_check=  $row['password'];				
  }
} 
 if ($email_check==$email){array_push($errors, "email already exists");}
if ($mobile_check==$mobile){array_push($errors, "mobile no. already exists");}
$password=md5($password); //encryption of password;
		// register user if there are no errors in the form
		if (count($errors) == 0) {
	$sql123 = "INSERT INTO user_register (	name,email,password,mobile ) 
			   VALUES('$name', '$email','$password','$mobile')";
if ($db->query($sql123) === TRUE) {
array_push($errors, "Thanks for submission<h4>");
$_SESSION['email'] = $email;
				$_SESSION['success'] = "You are now logged in";
				header('location: welcome.php');
} 
else { echo "Error: " . $sql123 ;}
}}

if (isset($_POST['login'])) {
		$email = mysqli_real_escape_string($db, $_POST['email']);
		$password = mysqli_real_escape_string($db, $_POST['password']);

if (empty($email)) {array_push($errors, "enter email");}
if (empty($password)) {array_push($errors, "enter password");}
$password=md5($password);
if (count($errors) == 0) {
$query = "SELECT * FROM user_register WHERE email='$email' AND password='$password'";
$results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) {
				$_SESSION['email'] = $email;
				$_SESSION['success'] = "You are now logged in";
				header('location: welcome.php');
			}else {array_push($errors, "Wrong username/password combination");}
			}}
			//log out
	if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['email']);
header("location: welcome.php");
}
?>
<?php  if (count($errors) > 0) : ?>
		<?php foreach ($errors as $error) : ?>
			<h5 class="errors" style="color: red;">	<?php echo $error ?></h5>
		<?php endforeach ?>
<?php  endif ?>
	

download Source code