#form


    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>hello world</title>
    <script src=
    "https://code.jquery.com/jquery-3.4.1.min.js">
        </script>


    
    </head>
    <body>


    <form id="myform"action="post.php" method="POST" name="myForm" >
       <label for="name">First name:</label>
    <input type="text" id="name" name="name"></br>

      <label for="name">Email:</label>
    <input type="email" id="email" name="email">



        <button type="button"  id="getbutton" onsubmit="return validateForm()">Submit</button>

    </form>

     <script>
            $(document).ready(function () {
      
                // On button click, get value
                // of input control Show alert
                // message box
                $("#getbutton").click(function () {
                    var name = $("#name").val();
                    var email = $("#email").val();

                     $.ajax({
                type: 'POST',
                url: 'post.php',
                 data:{name:name, email:email},
                success: function (data) {
                  
                }
              });
            
                });
            });
        </script>

    </body>
    </html>



    #post


    <?php

    include 'connection.php'; ?>

    <?php


    // $data=$_POST['data'];

    // $sql = "INSERT INTO student (name)VALUES ('data')";

    // if (mysqli_query($conn, $sql)) {
    //   echo "New record created successfully";
    // } else {
    //   echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    // }


              if (isset($_POST['name'])) {
                // code...
                 $name=$_POST['name'];
                 $email=$_POST['email'];
                  
            
                 $sql= mysqli_query($conn,"INSERT INTO student(name,email) VALUES('".$name."','".$email."')");
                if ( ! $sql ) {
                    echo " data is not insered";
                }else{
                   echo " data is  insered";

                   
                }

             }

    ?>


    #connection
    <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $db = "corephpdb";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password,$db );

    // Check connection
    if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
    }
    // echo "Connected successfully";
    ?>