By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
LahbabiGuideLahbabiGuide
  • الرئيسية
  • مزيج مِن أفكاري
    • مقالاتي
    • قصص قصيرة
    • سيناريوهات أفلام قصيرة
    • نصوص مسرحية قصيرة
  • أفكار المشاريع
  • قصص النجاح
  • أخبار تقنية
  • القرأن الكريم
Search
  • Advertise
© 2022 Zakariaelahbabi.com . Company. All Rights Reserved.
Reading: CRUD PHP MySQL Example and Source Code | With Ajax No Reloading
Share
Notification Show More
Latest News
bootstrap-clean-buttons-with-hover-effect-|-plain-button-ui-kit
Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit
Bootstrap
bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table
Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Bootstrap
upload-image-in-php-with-mysql-database-|-web-dev-trick
Upload Image In PHP With MySQL Database | Web Dev Trick
PHP
bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip
Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Bootstrap
php-age-calculator-program-|-calculate-age-in-php
PHP Age Calculator Program | Calculate Age In PHP
PHP
Aa
LahbabiGuideLahbabiGuide
Aa
  • مزيج مِن أفكاري
  • أخبار تقنية
  • تطوير الويب
  • أفكار المشاريع
Search
  • Home
    • Home 1
    • Default Home 2
    • Default Home 3
    • Default Home 4
    • Default Home 5
  • Categories
    • تطوير الويب
    • أخبار تقنية
    • أفكار المشاريع
    • مزيج مِن أفكاري
    • قصص النجاح
  • Bookmarks
  • More Foxiz
    • Sitemap
Follow US
  • Advertise
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
crud-php-mysql-example-and-source-code-|-with-ajax-no-reloading
LahbabiGuide > تطوير الويب > PHP > CRUD PHP MySQL Example and Source Code | With Ajax No Reloading
PHP

CRUD PHP MySQL Example and Source Code | With Ajax No Reloading

admin
Last updated: 2023/03/11 at 7:37 صباحًا
By admin
Share
5 Min Read
SHARE

CRUD PHP MySQL: Today I am sharing how to create a CRUD database app with PHP & MySQL. First, You should know CRUD standard for Create, Read, Update, & Delete.  If you are an experienced web developer, you must have created CRUD apps already. Maybe CRUD exists in accounting softwares. If you are a beginner in web development, you will experience lots of CRUD program in your future career. Basically, MySQL store data in SQL Database. After that, PHP fetches those Database tables and give users the power to play with CRUD actions.

Today I am sharing a simple CRUD grid with PHP and MySQL database.  This program is built in PHP, MySQL, HTML, Bootstrap & Ajax for smooth and not reloading page.  I did not create a CSS file for styling, this program uses default bootstrap styling.

You Also May Like

Upload Image In PHP With MySQL Database | Web Dev Trick

Build a Simple Quiz In PHP | Source Code

More PHP Programs

Requirement For Creating This CRUD App:

  • Basic knowledge of HTML
  • Basic Knowledge of Bootstrap
  • Knowledge of PHP & MySQL
  • Local Server Environment like Xampp, MAMP etc.
  • Any IDE or Notepad++

Follow step by step for creating this database app.

Create Database

Create a database name “phpcrud” After that, Create a table named “users” with 3 rows.
id int(11) NOT NULL,
name varchar(100) NOT NULL,
email varchar(100) NOT NULL

Make Sure check on A. I. (auto increment) in “id” section when you create. If you have any problem to create tables, just create database named “phpcrud” go to “SQL” section and paste these codes give below and press on go.

CREATE TABLE `users` (

  `id` int(11) NOT NULL,

  `name` varchar(100) NOT NULL,

  `email` varchar(100) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `users`

  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

COMMIT;

Connection to Database

Create a file named “db.php” for database connection and paste these codes.

<!— code by webdevtrick (https://webdevtrick.com) –>

$dsn = ‘mysql:host=localhost;dbname=phpcrud’;

$username = ‘root’;

$password = ”;

$options = [];

try {

$connection = new PDO($dsn, $username, $password, $options);

} catch(PDOException $e) {

}

Create Header File

I am creating is program dynamically. So, I have created separate file for header, index, and footer. Now create a file named “header.php” and paste these codes.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

<!doctype html>

<!— code by webdevtrick (https://webdevtrick.com) –>

<html lang=“en”>

  <head>

    <title>PHP CRUD | WEBDEVTRICK</title>

    <meta charset=“utf-8”>

    <meta name=“viewport” content=“width=device-width, initial-scale=1, shrink-to-fit=no”>

    <link rel=“stylesheet” href=“https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css”>

  </head>

  <body class=“bg-info”>

    <nav class=“navbar navbar-expand-lg navbar-light bg-light”>

  <a class=“navbar-brand” href=“https://webdevtrick.com”>WebDevTrick</a>

  <button class=“navbar-toggler” type=“button” data–toggle=“collapse” data–target=“#navbarSupportedContent” aria–controls=“navbarSupportedContent” aria–expanded=“false” aria–label=“Toggle navigation”>

    <span class=“navbar-toggler-icon”></span>

  </button>

  <div class=“collapse navbar-collapse” id=“navbarSupportedContent”>

    <ul class=“navbar-nav mr-auto”>

      <li class=“nav-item active”>

  <a class=“nav-link” href=“https://webdevtrick.com/”>Home </a>

      </li>

      <li class=“nav-item”>

        <a class=“nav-link” href=“create.php”>Add User</a>

      </li>

    </ul>

  </div>

</nav>

Create Index Page

Create a file named “index.php” and copy & paste these codes.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

require ‘db.php’;

$sql = ‘SELECT * FROM users’;

$statement = $connection->prepare($sql);

$statement->execute();

$people = $statement->fetchAll(PDO::FETCH_OBJ);

?>

require ‘header.php’; ?>

<div class=“container”>

  <div class=“card mt-5”>

    <div class=“card-header”>

      <h2>Users List</h2>

    </div>

    <div class=“card-body”>

      <table class=“table table-bordered”>

        <tr>

          <th>ID</th>

          <th>Name</th>

          <th>Email  Address</th>

          <th>Manage</th>

        </tr>

         foreach($people as $person): ?>

          <tr>

            <td> $person->id; ?></td>

            <td> $person->name; ?></td>

            <td> $person->email; ?></td>

            <td>

              <a href=“edit.php?id= $person->id ?>“ class=“btn btn-info”>Edit</a>

              <a onclick=“return confirm(‘Are you sure you want to delete this entry?’)” href=“delete.php?id= $person->id ?>“ class=‘btn btn-danger’>Delete</a>

            </td>

          </tr>

         endforeach; ?>

      </table>

    </div>

  </div>

</div>

require ‘footer.php’; ?>

Footer Page

Create a file named “footer.php” and paste these following codes. In footer file is linking with JQuery, Bootstrap & Ajax file.

<!— code by webdevtrick (https://webdevtrick.com) –>

    

    

    

  </body>

</html>

Create Page For Add User

php crud add user

Now create a page for adding new users in the database. Create a file named “create.php” and put these codes given below.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

<!— code by webdevtrick (https://webdevtrick.com) –>

require ‘db.php’;

$message = ”;

if (isset ($_POST[‘name’])  && isset($_POST[’email’]) ) {

  $name = $_POST[‘name’];

  $email = $_POST[’email’];

  $sql = ‘INSERT INTO users(name, email) VALUES(:name, :email)’;

  $statement = $connection->prepare($sql);

  if ($statement->execute([‘:name’ => $name, ‘:email’ => $email])) {

    $message = ‘data inserted successfully’;

  }

}

?>

require ‘header.php’; ?>

<div class=“container”>

  <div class=“card mt-5”>

    <div class=“card-header”>

      <h2>Create a User</h2>

    </div>

    <div class=“card-body”>

       if(!empty($message)): ?>

        <div class=“alert alert-success”>

           $message; ?>

        </div>

       endif; ?>

      <form method=“post”>

        <div class=“form-group”>

          <label for=“name”>Name</label>

          <input type=“text” name=“name” id=“name” class=“form-control”>

        </div>

        <div class=“form-group”>

          <label for=“email”>Email</label>

          <input type=“email” name=“email” id=“email” class=“form-control”>

        </div>

        <div class=“form-group”>

          <button type=“submit” class=“btn btn-info”>Create a User</button>

        </div>

      </form>

    </div>

  </div>

</div>

require ‘footer.php’; ?>

Update User Information

php crud edit user

Now create a page for edit users information. Create a file named “edit.php” and paste codes given below.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

<!— code by webdevtrick (https://webdevtrick.com) –>

require ‘db.php’;

$id = $_GET[‘id’];

$sql = ‘SELECT * FROM users WHERE id=:id’;

$statement = $connection->prepare($sql);

$statement->execute([‘:id’ => $id ]);

$person = $statement->fetch(PDO::FETCH_OBJ);

if (isset ($_POST[‘name’])  && isset($_POST[’email’]) ) {

  $name = $_POST[‘name’];

  $email = $_POST[’email’];

  $sql = ‘UPDATE users SET name=:name, email=:email WHERE id=:id’;

  $statement = $connection->prepare($sql);

  if ($statement->execute([‘:name’ => $name, ‘:email’ => $email, ‘:id’ => $id])) {

    header(“Location: /”);

  }

}

?>

require ‘header.php’; ?>

<div class=“container”>

  <div class=“card mt-5”>

    <div class=“card-header”>

      <h2>Update User</h2>

    </div>

    <div class=“card-body”>

       if(!empty($message)): ?>

        <div class=“alert alert-success”>

           $message; ?>

        </div>

       endif; ?>

      <form method=“post”>

        <div class=“form-group”>

          <label for=“name”>Name</label>

          <input value=“ $person->name; ?>“ type=“text” name=“name” id=“name” class=“form-control”>

        </div>

        <div class=“form-group”>

          <label for=“email”>Email</label>

          <input type=“email” value=“ $person->email; ?>“ name=“email” id=“email” class=“form-control”>

        </div>

        <div class=“form-group”>

          <button type=“submit” class=“btn btn-info”>Update person</button>

        </div>

      </form>

    </div>

  </div>

</div>

require ‘footer.php’; ?>

Delete User

Create a file for delete any user. So, create a file named “delete.php” and paste these codes.

require ‘db.php’;

$id = $_GET[‘id’];

$sql = ‘DELETE FROM users WHERE id=:id’;

$statement = $connection->prepare($sql);

if ($statement->execute([‘:id’ => $id])) {

  header(“Location: /”);

}

That’s It. You Hava Successfully created a CRUD PHP MySQL app with ajax no reloading feature. If you did not understand whole steps, Don’t worry download source code from here.

Password: webdevtrick.com

Download Source Code

I hope this article will be helpful to you. If you have any doubt comment down below, I will reply to your comment as soon as possible.

Thanks For Visiting, Keep Visiting.

You Might Also Like

Upload Image In PHP With MySQL Database | Web Dev Trick

PHP Age Calculator Program | Calculate Age In PHP

Generate Random Numbers In PHP | Numbers In Sort By Order

PHP Shopping Cart | Add to Cart Feature In PHP & MySQL

New Years Countdown Timer With jQuery and Bootstrap Layout | Time Left

TAGGED: crud database app, crud in php, crud php mysql, PHP, php and mysql, php source code, php tutorial, Web Development
admin مارس 11, 2023
Share this Article
Facebook Twitter Pinterest Whatsapp Whatsapp LinkedIn Tumblr Reddit VKontakte Telegram Email Copy Link Print
Previous Article domain-availability-checker-in-php-|-get-source-code Domain Availability Checker In PHP | Get Source Code
Next Article php-calculator-example-with-source-code-|-basic-calculator-in-php PHP Calculator Example With Source Code | Basic Calculator in PHP
Leave a comment Leave a comment

اترك تعليقاً إلغاء الرد

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *

Stay Connected

235.3k Followers Like
69.1k Followers Follow
11.6k Followers Pin
56.4k Followers Follow
136k Subscribers Subscribe
4.4k Followers Follow
- Advertisement -
Ad imageAd image

Latest News

bootstrap-clean-buttons-with-hover-effect-|-plain-button-ui-kit
Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit
Bootstrap مارس 11, 2023
bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table
Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Bootstrap مارس 11, 2023
upload-image-in-php-with-mysql-database-|-web-dev-trick
Upload Image In PHP With MySQL Database | Web Dev Trick
PHP مارس 11, 2023
bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip
Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Bootstrap مارس 11, 2023
//

We influence 20 million users and is the number one business and technology news network on the planet

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

[mc4wp_form id=”847″]

LahbabiGuideLahbabiGuide
Follow US

© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.

Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc..

[mc4wp_form]
Zero spam, Unsubscribe at any time.

Removed from reading list

Undo
Welcome Back!

Sign in to your account

Lost your password?