Tuesday, 20 February 2018

Insert Data In Mysql Using PHP

InsertDemo.html
<html>
<head>
<title> Insert Demo</title>
</head>

<body>
<h1 style="text-align:center;color:Indigo">Insert data  in mysql using php </h1>

<form method="POST" action="my_sql2.php">
<table border="1">

<tr>
<td>ID :</td><td> <input type="number" name="id"/></td></tr>
<tr>
<td>Name:</td><td><input type="text" name="name" required/></td></tr>
<tr>
<tr>
<td>D.O.B</td><td><input type="date" name="dt"/></td></tr>
<td>Email:</td><td><input type="email" name="email"/></td></tr>
<tr>
<td>Phone:</td><td><input type="number" name="phone"/></td></tr>
<tr>
<td>Address:</td><td> <textarea name="addr" rows="3" cols="30"></textarea></td></tr>

<tr>
<td>Qualification:</td><td>
<select name="Qualification">
<option value="BE">BE</option>
<option value="MCA">MCA</option>
<option value="B.Sc">B.Sc</option>
<option value="M.Sc">M.Sc</option>
<option value="Other">Other</option>
</select></tr>
</table><br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="insert" value="Insert">

</form>
</body>
</html>

my_sql2.php

?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname= "enquiry";

$conn = new mysqli($servername, $username, $password, $dbname);

if(isset($_POST['subtn']))
{
         
          $name1=$_POST['name'];
          $email1=$_POST['email'];
          $phone1=$_POST['phone'];
          $addr1=$_POST['addr'];
          $qual=$_POST['Qualification'];
         
          $sql= "INSERT INTO student VALUES('$name1', '$email1', '$phone1','$addr1', '$qual')";
         
          if(!mysqli_query($conn,$sql))
                   {
                                      die('Error'.mysqli_error($conn));
                   }
          else
                   {
                             echo '<script language="text/javascript">';
                             echo '<alert ("Sucessfully registered");
                             //location.href="my_sql.html">';
                             echo '</script>';
                   }
}
?>
Output:
             Insert data in mysql using php

ID :
Name:
D.O.B
Email:
Phone:
Address:
Qualification:

                        
Note:
Create database  and table in phpMyadmin

database_name:enquiry
table_name: student
Field_name: ID ,Name,D.O.B,Email,Phone ,Address and Qualification

Field_name    datatype          size      Auto_increment
 ID                     int                 10          true or check(primary key)
 Name               varchar          10
D.O.B               Date              10
Email                varchar          10
Phone                BIGINT        10      
Address            varchar          10
Qualification     varchar         10

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...