,

Add Edit and Delete Records with Basic PHP and MySQL


First, prepare your database. 


In my case, i named my database as ks_add_edit_delete and 
my table as info.

Next, Create your configuration file to connect in your database. 

Create a new file and name it as config.php
#Image Creating a config.php
Open config.php in your text editor and insert this code.

Next is to create your index.php in your host directory and copy the following codes.

Do not forget to require the config file you created earlier.

Create html tags and insert <h1> tags inside the <body> as a page title reference.
<a> tag is also added that is pointing to add.php that you will be creating later.

After it, Create a table where you want to display your records.
Place the following code below to fetch all the records from the database and display it on the table body.

Next is for adding a new record. You need to create a new page and name it to add.php.

Create a form with your fields in the add.php

Validation needs to be done after the declaration of the variables that we will be needing in the result summary or errors.

Next is the edit.php, It is like the add.php but you need the id of the record in order to fetch the data stored in your database.

Lastly is delete.php . Get the id of the record and delete the row where the value of the id matches.

Your final output should look like the following.







You can download the full source code below.

SOURCE CODE
1. Download the source code & place it on your host.
2. Create a database ‘ks_add_edit_delete’.
3. Import the sql file located at the source code's folder.
4. Test it on your host.

DOWNLOAD IT HERE -> DOWNLOAD

Enjoy !
Please share this if you find it helpful. Thank you.
Share:

No comments:

Post a Comment