Data insertrd in database using php

  • Here there are two files one for creating form in html and second for connecting with database in php.

1.This file is form in html create save this file as index.php


<?php
?>
<html>
<head>
<title></title>
</head>
<body>
<form action="insert.php<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<table align="center" style="margin-top: 80px">
<tr><!-- prepared by vishal Rathod -->
 <td>Name :</td>
  <td>
   <input type="text" name="name" required="required">
  </td>
</tr>
<tr>
 <td>Email :</td>
  <td>
   <input type="text" name="email" required="required" >
  </td>
</tr>
<tr>
 <td colspan="2" align="center"><input type="submit" name="submit" value="submit"></td>
</tr>   <!-- prepared by vishal Rathod -->
</table>
</body>
</html>


  • after in your browser type localhost/folder_name/index.php
  • this is output of this file..


2.second file create for connect database with two fields and validate email address
   save this file as insert.php


<?php

 if(isset($_POST['email'])==true && empty($_POST['email'])==false)
 {
     $b=$_POST['email'];
   if(filter_var($b,FILTER_VALIDATE_EMAIL)==true) /*for valid email address*/
   {
     echo "that's valid email address.";
     $a=$_POST['name'];
     $conn=mysqli_connect('localhost','root','','dbm'); //for connection database
     $query="INSERT INTO `form`( `name`, `email`) VALUES ('$a','$b')";
     $run=mysqli_query($conn,$query); //run the query
    if($run==true)                // prepared by vishal Rathod
        echo "\nData inserted succesfully.";
      else
        echo "Error";
   }
   else
     echo "Not valid email address";   
 }
 echo "\n\tprepared by vishal Rathod"

?>



  • write two fields details then click on button submit

Comments

Popular posts from this blog

program that compresses windows BMP image file using java

react-native multiselect dropdown