PHP AJAX CRUD - 1 | How to Fetch data from database using jquery ajax in php HINDI

Hello Guys., so in this above video, we are learning about how to fetch the data from database using jQuery, Ajax in php.

So.. Let's get started, First take a template, orelse you can follow the Video template where we are using Bootstrap for designing the view. goto and copy the starter template and continue with below code:

Step 1: Create a table named students below code:

Create a table as per below code in your database:

CREATE TABLE students (
    id int,
    fname varchar(100),
    lname varchar(100),
    class varchar(100),
    section varchar(100)

Step 2: Create a file named index.php and paste the below code:

<!doctype html>
<html lang="en">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

    <title>PHP - AJAX - CRUD</title>

    <div class="container mt-5">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                            PHP - AJAX - CRUD | Data without page reload using jquery ajax in php.
                            <button type="button" class="btn btn-primary float-right" data-toggle="modal" data-target="#Student_AddModal">
                    <div class="card-body">
                        <div class="message-show">

                        <table class="table table-bordered table-striped">
                                    <th>First Name</th>
                                    <th>Last Name</th>
                            <tbody class="studentdata">

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src=""></script>
    <script src="" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

        $(document).ready(function () {

        function getdata()
                type: "GET",
                url: "ajax-crud/fetch.php",
                success: function (response) {
                    // console.log(response);
                    $.each(responsefunction (keyvalue) { 
                        // console.log(value['fname']);
                                '<td class="stud_id">'+value['id']+'</td>\
                                    <a href="#" class="badge btn-info viewbtn">VIEW</a>\
                                    <a href="#" class="badge btn-primary edit_btn">EDIT</a>\
                                    <a href="" class="badge btn-danger">Delete</a>\


Step 3: Create a file named fetch.php inside ajax-crud and paste the below code:

First Create a folder name ajax-crud and create a file named fetch.php and paste the below code:


$conn = mysqli_connect("localhost","root","","phpcrud");

$query = "SELECT * FROM students";
$query_run = mysqli_query($conn$query);
$result_array = [];

if(mysqli_num_rows($query_run) > 0)
    foreach($query_run as $row)
    header('Content-type: application/json');
    echo json_encode($result_array);
    echo $return = "<h4>No Record Found</h4>";


© Copyright - 2018 - 2021 | All rights reserved at Funda of Web IT