What is CRUD?
CRUD stands for Create, Read, Update, and Delete. It is a set of operations that are commonly used in database management systems to perform basic data manipulation tasks such as adding new records, reading existing records, updating existing records, and deleting records.
In web development, CRUD is often used to create web pages that allow users to interact with a database through a web interface. For example, a CRUD application may have a page that displays a list of records from a database, a page that allows users to add new records, a page that allows users to edit existing records, and a page that allows users to delete records.
In this tutorial we are building a dynamic CRUD application with php mysqli prepared statements
Let's start by creating it.
Folder Structure:
Step 1:
Create a database and name it listing. once you create the database then Execute the following SQL query to create a table named customers inside your MySQL database listing.
Step 2:
Create the Config File (config.php) inside xampp/htdocs/crud_mysql_prepared_statements/.
This file is used to establish a connection to the database.It contains the host, username, password, and database name used to connect to the database.It also checks if the connection is successful and displays an error message if the connection fails.
Lets copy and paste the following code in config.php file.
Step 3:
Create header.php file (Common Header Include for All Pages) inside xampp/htdocs/crud_mysql_prepared_statements/.
This file is included in all pages of the CRUD application to keep the code dry and clean. It includes the config.php file for database connection, and also includes the CSS and JS files needed for the layout and functionality of the application.
Copy and paste the following code in header.php file.
Step 4:
Create index.php file(Customer Data Table) inside xampp/htdocs/crud_mysql_prepared_statements/.
This is the main page of the CRUD application, where all the customer data is displayed in a table format. It retrieves data from the customers table in the database and displays it in a table format. It also provides options to add, edit and delete customer records.
Copy and paste the following code in index.php file.
Step 5:
Create add.php file(Add New Customer Form) inside xampp/htdocs/crud_mysql_prepared_statements/.
This file contains the HTML form for adding new customer data to the database. It allows users to input their data and submit it to the server for insertion into the database.
Copy and paste the following code in add.php file.
Step 6:
Create add_save.php file(Save New Customer Data) inside xampp/htdocs/crud_mysql_prepared_statements/.
This file is responsible for processing the form data from add.php and inserting it into the database. It also contains validation and error-handling code to ensure that the data is correct before insertion.
Copy and paste the following code in add_save.php file.
Step 7:
Create update.php file(Update Customer Form) inside xampp/htdocs/crud_mysql_prepared_statements/.
This file contains the HTML form for updating existing customer data in the database. It allows users to edit existing customer data and submit it to the server for updating in the database.
Copy and paste the following code in update.php file.
Step 8:
Create update_save.php file(Save Updated Customer Data) inside xampp/htdocs/crud_mysql_prepared_statements/.
This file is responsible for processing the form data from update.php and updating the data in the database. It also contains validation and error-handling code to ensure that the data is correct before updating.
Copy and paste the following code in update_save.php file.
Step 9:
Create delete.php file(Delete Customer Data)inside xampp/htdocs/crud_mysql_prepared_statements/.
This file is responsible for deleting customer data from the database. It receives the customer ID from index.php and deletes the corresponding record from the database.
Copy and paste the following code in delete.php file.
After a long journey finally we've finished our CRUD application with PHP and MySQL.
If you have any problem with code, please leave me a comments, i am here to help you.