/* */ Click to Join Live Class with Shankar sir Call 9798158723

INSERT Query in MySql using PHP ?


After creating a table with required fields in a database we need to insert information into it, for that we use a insert query to insert the information of a form into the database table in MySql.

Inserting information on the page.

we need to create a page for entering values in the table.(form.php)
 <!DOCTYPE html>
 <html lang="en">
 <head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>form page</title>
 </head>
 <body>
 <form name="f" method="POST" action="insert_action.php">
 Enter name<input type="text" name="t1"><br>
 Enter roll<input type="number" name="t2"><br>
 Enter email<input type="email" name="t3"><br>
 Enter password<input type="password" name="t4"><br>
 <input type="submit">
 </form>
 </body>
 </html>

Inserting information in the database table.

Connectivity page for inserting values in the database.(insert_action.php)
 <!DOCTYPE html>
 <html lang="en">
 <head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Connectivity Page</title>
 </head>
 <body>
 <?php
  $n=$_REQUEST["t1"];
  $r=$_REQUEST["t2"];
  $e=$_REQUEST["t3"];
  $p=$_REQUEST["t4"];
  $servername="localhost";
  $username="root";
  $password="";
  $db="project";   */suppose project is our database name. */
  $conn=mysqli_connect($servername,$username,$password,$db);
  if(!$conn)
  {
   echo"not connected";
  }
  $q="INSERT INTO `table1`(`name`, `roll`, `email`, `password`)
  values('$n','$r','$e','$p')";  */ suppose table1 is our table name. */
  $qu=mysqli_query($conn,$q);
  ?>
 </body>
 </html>