Simple CRUD application using PHP and MYSQL


What is  a CRUD system? CRUD is an substitution word for a bunch of words. Those words are Create, Retrieve, Update and Delete. These are the main basic four operations done in a web system. With the database connection, we can perform all these operations using PHP and MYSQL. Here I will create a simple system for a user with all theses features. I would not be able to explain all the files since it will take long time. But I will definitely upload the source files to my GitHub account. You can download and try it.

As the fundamentals , You need to create a database and the db connection first. Use the SQL file included in my GitHub Repo to easily create the database. How to do it? 
  • Go to phpmyadmin and create the database as testdb.
  • Then select the db from left panel and look for the operation called import.
  • Click on it and choose the downloaded testdb.sql file.
  • Finally click on Go button. Then the database will be created automatically.
Then you need to start coding the system. As usual, create the index file and the other files you need to build up this system. Create a stylesheet called  style, for styling. I have included the all style in it to make my work easy.

How will the system look like?

Login page



Registration page



Homepage
                                  


Profile page



Update profile page



Skills page



Add a skill page




Update skill page



Here I will explain only few special occasions you will meet while coding. You can refer to these notes when you get into trouble.

isset Function

This is an in-built function in PHP to check whether something is existing or not simply. I will use an example from a code.


This means if there is a button called reg and if it is clicked for a a submission, do the the following things included in if clauses. We use this function when we code the logic for a submit button within the page in which the button is included. We can use it to check a session also.


md5 Function

This is  a function used to increase the security to some extent. It can be used for the password. After we code the password within the md5 function, it will be converted into a long random code. The password will be saved in the database as a code and the exact password will be known only by the man who create the password. But if two persons use the same text or number for the password like 123, the random code will be the same for both persons. This function only assigns a unique code for a particular phrase.


$_GET Method

Here, I used this method to pass some values to the URLs. This helps a lot when you need to fetch some data of one and only person or item. Example from the code;


When the button called "ADD SKILL" is clicked, the value of uname is passed through the URL of add_skill.php page. If we want to get this value for our code in a particular page, we can get it using this GET method like this.



Header location Function

Header function is used to redirect to a web page, after something is done since there is no need of staying the particular page. The page you want to go next, is included in the function.
Example;


Here, I use the login code to explain. After entering the username and password, query is checking for an existing user in the database. If there's any record matching with those two inputs, headder function is executed to load the homepage for that user.

Script function; window.location

This is a Javascript to load a web page after hitting ok for a notification coming as a JS alert. This will set the current window to the given page within the script. Use of this...


I used this to give a notification saying "Profile Updated" after I update the profile for a user. After updating, new location of system will be the profile.php page.


Script function; password check

Javascript code was used to match the password and confirm password values. Code will like this.


I have used two password for password lines as password and cpassword. Getting this ID values, the function is executed. After entering password usually confirm password is entered. Until the confirm password matches with the password, a message will be shown as Password not matching. When both of them get matched, the message called Password matching will be displayed.


$SESSSION

This is one of the most important thing when you have to handle the user accounts. This session is a particular time or space allocated for a user. It has a self destroying time. You will log into web sites and then you will be doing some other work. After some time if you visit the site there will be error called session has expired or timeout or something like this. I think you got the idea. When you need to start a session in a code for a web page, use session_start() and when you want to destroy it, use session_destroy(). When we use them? Usually a user is logged into the system and the user is logged out from the system.

I think this explanation is enough for now. Some critical things have been explained here. But if you more questions or things to be cleared, drop a comment here. I will try my best to explain.
Thank You! 

You can download the source file from the below link.


Admin Semoga Informasi Yang Diberikan Melalui Web Ini Dapat Bermanfaat Bagi Saudara/i

No comments for "Simple CRUD application using PHP and MYSQL"