Killersites Forum Blog – Basic PHP System: View, Edit, Add, Delete records with MySQLi

Hey Everyone,

Here’s some helpful info on a basic PHP system, from our Killersites Community Forum!

Basic PHP System: View, Edit, Add, Delete records with MySQLi

This is a revised version of my previous tutorial (http://www.killersit…eteadd-records/) which uses MySQLi rather than regular MySQL to connect to the database. MySQLi, often called MySQL Improved, has several advantages over regular MySQL, including support for prepared statements (which helps prevent SQL injection, a common security issue) and object-oriented code. I’ve also provided a modified view.php file that shows one way to do basic pagination.

I have also recorded a 8 part video tutorial (a bit over an an hour worth of video) showing how to build this system and explaining it as I go. It’s available in the KillerSites University ( – subscription required) under PHP > PHP CRUD Videos.

(Anyone with PHP knowledge is welcome to comment on the code. If there are issues I haven’t noticed, please let me know. Do realize that it is intended for beginners, so I didn’t want to do anything too advanced that might lead to confusion. Yes, I realize I could use OOP, or could separate some of these out into methods, etc. etc.)

OK… Here’s some code for you to play with. It’s a basic system that allows you to:
— view existing records
— edit existing records
— delete existing records
— add new records

Online demo:

Basically, just imagine that you are in charge of a sports team, and you want to keep a list of all your player’s contact information. The code I’ve created could be a starting point for that (it only includes fields for their first name/last name, but could obviously could be expanded to use more fields).

This is just a basic starting point for projects that require view/edit/delete functionality. I know it may seem a lot to understand at first, but read all the comments in the code — I try to explain what I am doing step by step. I’m also happy to help with any questions (please post questions in a new topic.)

How to create a system that allows a user to add/edit/remove data in a database seems to be a commonly asked topic, so I may adapt this into an actual tutorial at some point in the future.

— You’ll need to create a database (I named mine ‘records’ but it can be changed) using PHPMyAdmin
— Save the included sql file on your desktop as a .txt file
— Once you’ve created the database, make sure the database is selected, then click the “import” tab
— Select the .txt file on your desktop, and import it into your database. PHPMyAdmin will create all of the necessary tables/import some test data for you to play with

Written by: Ben

For the test data and the rest of the post, click here!



Tags: ,

This post was written by:

This entry was posted on Monday, December 13th, 2010 at 6:43 am and is filed under Forum Blog. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.