How to Add Data in Database using PHP coding

  1. Home
  2. Tags
  3. How to Add Data in Database using PHP coding

How to Add Data in Database using PHP coding

Create A Form using the Input field

 

Open Database in Google Chrome using this command

localhost/phpmyadmin

create Database names like as 

Database Name
School

create Table names like as

Table Name
tbl_register

 

Make a Form using a different name to match with the database
 

<?php
    if(isset($_POST['addrecord'])){
     $username=$_POST['username'];
     $email=$_POST['email'];
     $phone=$_POST['phone'];
   try{
     $sql = "INSERT INTO tbl_register (username,email,phone) VALUES ('$username','$email','$phone')";
     $conn->exec($sql);
     echo "Record Insert Successfully";
     }catch(PDOException $e){
 echo  echo "Failed to Enter Data in Database";
    }
}
?>