Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Wednesday 4 January 2017

program to create simple form and store details in database

-------------------------------FORM--------------------------------

<html>

<head><title>Form</title></head>

<form action="dbconn.php" method="post">

Enter First name:<input type ="text" name="First" value =""  placeholder="enter name" ></br>

Enter date of Birth:<input type ="date" name="date" value =""  placeholder="enter date of birth" ></br>

Enter Email: <input type ="text" name="email" value =""  placeholder="enter Email" ></br></br>

Enter pass : <input type="password" name="pass" value="" placeholder="enter Pass">&nbsp;&nbsp;&nbsp;

<input type="submit" name ="submit" value ="click here";>

</form>

</html>



--------------------------PHP Code------------------------------


<?php
 $Name=$_POST['first'];
$Date=$_POST['date'];
$Email=$_POST['email'];
$password=$_POST['pass'];
$host='localhost:3306';
$user='root';                        
/* User name of Localhost*/
$pass='';                               /*Password of Localhost*/

$dbname='first';                 /*Name of Database  created in php My Admin*/
$conn=mysqli_connect($host,$user,$pass,$dbname);
if(!$conn)
{
die ('could not connect :'.mysqli_connect_error());
}
echo('connectd successfully <br/>');

/* To crate a table */

$sql="Create table Records(name varchar(10),DOB varchar(10),email varchar(10),Password varchar(10))";

/* To insert records in the table*/

$sql1="insert into Records(name,DOB,email,Password) VALUES('$Name','$Date','$Email','$password')";
if(mysqli_query($conn,$sql))
{
echo("<br/>");
echo 'data inserted  successfully<br/>';
}
else
{
echo ' coudnt connect'.mysqli_error($conn);
}
mysqli_close($conn);
?>






No comments:

Post a Comment