PHP (Core & Framework)

HOW TO CREATE A REGISTRATION FORM USING PHP !!

In this article we shall learn about how to create a registration form using php. For this you should have pre-requisite knowledge of how to create a basic form using HTML. 

After this a sql query is passed to insert the values in respective fields after pressing the submit button. This is done by :-

$sql=“ query “;

“mysqli_query(…)” is the function that executes the SQL queries.

“$query” is the SQL query to be executed

SYNTAX:

<?php

mysqli_query($connect,$query) ;

?>

CREATE TABLE IF NOT EXISTS `users` (

  `user_id` int(11) NOT NULL,

  `user_type` tinyint(4) DEFAULT ‘1’,

  `name` varchar(250) NOT NULL,

  `age` varchar(100) NOT NULL,

  `email` varchar(100) NOT NULL,

  `userpass` varchar(25) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

<!DOCTYPE html>

<html>
<head>
	<title>Registration Form</title>
</head>
<body>
	<h1><u>USER REGISTRATION FORM</u></h1><br><br>
	<?php
	include("connect2.php");

if(isset($_POST['submit']))
{
	$name=$_POST['pname'];
	$ut=$_POST['user_type'];
	$email=$_POST['pmail'];
	$pass=$_POST['ppass'];
	

	$sql="insert into users(name,user_type,email,userpass) values ('$name','$ut','$email','$pass')";

	if(mysqli_query($conn,$sql))
	{
		echo " Record Added Successfully !!!";
	}
	else
		echo "error:".$sql."<br>".mysqli_error($conn);
}
else
{
?>	
	<form method="post" name="myform" action="">
		Name:<input type="text" name="pname"><br>
		User Type:<select name="user_type">
			<option value=1>Staff</option>
			<option value=2>Patient</option>
		</select><br>
		E-mail:<input type="text" name="pmail"><br>
		Password:<input type="Password" name="ppass"><br>
		
		<input type="submit" name="submit" value="Register">
	</form>

<?php
}
?>
</body>
</html>




Posted by – Rhythm Arya