how to create simple registration form in php

Registration-form


Registration form in PHP
PHP registration form
How to insert data in a table?
First, we create database name 'mydata'
Second, we create table name 'employee'
Here, we're using 5 field names to insert data in MySQL:

<html> <head> <title>registration</title> </head> <form method="post" action="registration.php"> First Name:<br> <input type="text"placeholder="First name" name="FName"> <br>Last Name:<br> <input type="text" placeholder="Last Name" name="LName"> <br>Country Name:<br> <input type="text" placeholder="Country Name"name="Country"> <br>Email Id:<br> <input type="Email"placeholder="Email Id" name="Email"> <br> <br><br> <input type="submit" name="save" value="submit"> </form> </div> </body> </html> <?php $servername='localhost'; $username='root'; $password=''; $dbname = "mydata";/* database name */ $conn=mysqli_connect($servername,$username,$password,"$dbname"); if(isset($_POST['save'])) { $FName = $_POST['FName']; $LName = $_POST['LName']; $Country = $_POST['Country']; $Email = $_POST['Email']; /* insert data in table */ $sql = "INSERT INTO employee (FName,LName,Country,Email) VALUES ('$FName','$LName','$Country','$Email')"; if (mysqli_query($conn, $sql)) { echo "successfully registrastion"; } else { echo "Error: " . $sql ." " . mysqli_error($conn); } mysqli_close($conn); } ?>


Now create a table employee and insert the following data

CREATE TABLE `employee` ( `Id` int(10) NOT NULL AUTO_INCREMENT, `FName` varchar(50) NOT NULL, `LName` varchar(50) NOT NULL, `Country` varchar(50) NOT NULL, `Email` varchar(50) NOT NULL, UNIQUE KEY `userid` (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=62 ;


Method:2
You may also like
Same database and also you can the same table and same insert data into the database.
The first method and the second few are changes.

<html> <head> <title>registrastion</title> </head> <form method="post" action="regi.php"> First Name:<br> <input type="text"placeholder="First name" name="FName"> <br>Last Name:<br> <input type="text" placeholder="Last Name" name="LName"> <br>Country Name:<br> <input type="text" placeholder="Country Name"name="Country"> <br>Email Id:<br> <input type="Email"placeholder="Email Id" name="Email"> <br> <br><br> <input type="submit" name="save" value="submit"> </form> </div> </body> </html> <?php $con=mysqli_connect("localhost","root","","regi"); if(isset($_POST['save'])) { $FName = $_POST['FName']; $LName = $_POST['LName']; $Country = $_POST['Country']; $Email = $_POST['Email']; /* insert data in table */ $sql = "INSERT INTO student (FName,LName,Country,Email) VALUES ('$FName','$LName','$Country','$Email')"; if (mysqli_query($con, $sql)) { echo "successfully registrastion"; } else { echo "error ocurred "; } mysqli_close($con); } ?>



Now create a table in MySQL

CREATE TABLE `student` ( `id` int(10) NOT NULL AUTO_INCREMENT, `FName` varchar(50) NOT NULL, `LName` varchar(50) NOT NULL, `Country` varchar(50) NOT NULL, `Email` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;




Comments