Develop Bootstrap-4 Signup Form in PHP

 How to Develop Bootstrap-4 Signup Form in PHP and MySQL


e-trainings-Bootstrp4-signup

 

This article teaches you how to use bootstrap 4 in developing signup form. Bootstrap supports HTML form controls such as textbox, password, email, radio buttons, checkboxes, textarea, buttons and other controls available in html5. So Using some of these controls we are developing a signup form. This code also has MySQL code to store form data in a database. If needed, can enable those commented lines.

 

coding-zon-bs4-form

 

 

 

 bs4-registration-form.php

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<title>e-trainings Demo on registration form using bootstrap -4</title>
</head>
<body>
<div class="container-fluid"  mt="50">

<div class="row margin-top-30">

<div class="col-lg-3"></div>
<div class="col-lg-8 col-md-8">

<h1>Registration Form</h1>
<?php
	
	if(isset($_POST["submit"])){
		
		define('DB_SERVER','localhost');
		define('DB_USER','root');
		define('DB_PASS' ,'');
		define('DB_NAME', 'coding-zon');
		
		$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
		
		
		$username = $_POST["username"];
		$password = $_POST["password"];
		$cpassword = $_POST["cpassword"];
		$email = $_POST["email"];
		$gender = $_POST["gender"];
		$languages= $_POST["speaks"];
		$country = $_POST["country"];
		$address = $_POST["address"];
		
		
		
		print "<h2>Your details are as follows :</h2><br>";
		
		print "username: ".$username."<br>";
		print "password: ".$password."<br>";
		print "cpassword: ".$cpassword."<br>";
		print "email: ".$email."<br>";
		 
		print "Country: ".$country."<br>";
		print "<br>Spoken Language:<br>";
		foreach($languages as $lang)
		{
		print $lang."<br>";
		}

		print "Gender: ".$gender."<br>";

		print "Address: ".$address."<br>"
 
                /* 
 
		if($password != $cpassword) die ("conformpassword not matched");
		
		
		$query = "INSERT into register(username,password,email,country,gender,address)
		VALUES('$username','$password','$email',$country,'$gender','$address')";
		
		$result=mysqli_query($con,$query );
		
		if($result){
		?>
		<div><span class="success"></span><h1>Registration Success</h1></div>
		
		<?php
		}
		else{*/
		?>
		
		<div><h1>Oops!! Something went wrong.</h1></div>
		<?php
		//}    
	//}  
?>


<form name="regi-form" action="" method="post">
	
	
	<div class="form-group row">
		<label for="inputUsername" class="col-sm-2 col-form-label">Username</label>
		<div class="col-sm-8">
			<input type="text" class="form-control" name="username" placeholder="Username">
		</div>
	</div>
	
	
	<div class="form-group row">
		<label for="inputEmail" class="col-sm-2 col-form-label">Email</label>
		<div class="col-sm-8">
			<input type="email" class="form-control" name="email" placeholder="Email">
		</div>
	</div>
	<div class="form-group row">
		<label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
		<div class="col-sm-8">
			<input type="password" class="form-control" name="password" placeholder="Password">
		</div>
	</div>
	<div class="form-group row">
		<label for="inputPassword2" class="col-sm-2 col-form-label">Confirm Password</label>
		<div class="col-sm-8">
			<input type="password" class="form-control" name="cpassword" placeholder="Confirm Password">
		</div>
		
	</div>


<div class="form-group row">
	<label for="inputCountry" class="col-sm-2 col-form-label">Country</label>
	<div class="col-sm-8">
		
		
		<select class="form-control" name="country">
			<option selected>Country</option>
			<option value="india">India</option>
			<option value="usa">USA</option>
			<option value="uk">UK</option>
		</select>
	</div>
</div>

	
<div class="form-group row">
	<label for="inputLanguage" class="col-sm-2 col-form-label">Languages known</label>
	<div class="col-sm-8">
		
		<div class="form-check-inline">
			<label class="form-check-label" for="check1">
				<input type="checkbox" class="form-check-input" id="check1" name="speaks[]" value="English" checked>English
			</label>
		</div>
		<div class="form-check-inline">
			<label class="form-check-label" for="check2">
				<input type="checkbox" class="form-check-input" id="check2" name="speaks[]" value="hindi">Hindi
			</label>
		</div>
		
		<div class="form-check-inline">
			<label class="form-check-label" for="check2">
				<input type="checkbox" class="form-check-input" id="check2" name="speaks[]" value="french">French
			</label>
		</div>
		
	</div>
</div>
<div class="form-group row">
	<label for="form-check-label" class="col-sm-2 col-form-label">Gender</label>
	<div class="col-sm-8">
		<div class="form-check-inline">
			<label class="form-check-label">
				<input type="radio" class="form-check-input" name="gender" value="male" checked>Male
			</label>
		</div>
		<div class="form-check-inline">
			<label class="form-check-label">
				<input type="radio" class="form-check-input" name="gender" value="female">Female
			</label>
		</div>
		
	</div>
</div>


<div class="form-group row">
	<label for="form-check-label" class="col-sm-2 col-form-label">Address</label>
	<div class="col-sm-8">
	<textarea cols="30" rows="5" class="form-control"  name="address" placeholder="Address"></textarea>
	</div>
</div>


<div class="form-group row">
	<label for="" class="col-sm-2 col-form-label"></label>
	<div class="col-sm-10">
		<button type="submit" name="submit" class="btn btn-primary">Sign Up</button>
	</div>
</div>
</div>




</form> 

</div>

<div class="col-sm-3" ></div>


<!--  JavaScript -->

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

</body>
</div>
</body>
</html>

 

 

 

Comments

Popular posts from this blog

Using javascript pass form variables to iframe src

Creating a new PDF by Merging PDF documents using TCPDF

Import excel file into mysql in PHP