PHP Simple CRUD Application Script

PHP Simple CRUD Application Script Zip:

Download

What is CRUD?

CRUD refers to the four basic types of Database operations: Create, Read, Update, Delete. Most applications and projects perform some kind of CRUD functionality.

Once you learn about these CRUD operations, you can use them for many projects. For an example, if you learn how to create student table with multiple columns, you can use similar approach to create employee table or customers table.

About Simple CRUD Script:

We have created a Simple CRUD (Create/Read/Update/Delete) Application in PHP that is easy to understand. You can directly download all the code/database using the Download button.

This CRUD Script has the minimum number of functions required, so that anybody can easily understand the code. This script does not ensure security and data validation. So, if you want to use this script for your live project, please make sure to validation user data.

How to run CRUD Script:

You just need to run the given code files and database at your server. This script should run properly after database setup on most local server. But it may require few configuration changes on remote/live server.

  • Download CRUD Script Zip file and extract it.
  • Copy complete crud folder into your local server (in htdocs or www)
  • Create a new database “crud_db” (You can use PHPMyAdmin)
  • Import database.sql file from crud folder into database “crud_db”
  • Now run files from crud folder using your server/folder path (For example: http://localhost/crud/)
  • It should works properly. You can Add some user data. Then you can test Edit/Update/Delete-User functions as well

You can see code from all the files in this tutorial. You can find basic description in comments as well.

config.php file store information about the database host, username and password. Most of the local server works with given detail. You can change as per your host and database details.

database.sql is a database file. You can to create a database, after downloading the crud script. You can either run commands from above mysql file or simply import this ‘database.sql’ file into database (example using PHPMyAdmin).

index.php file is the main file which include configuration file for database connection. Then it display all users list using MySQL Select Query. However, you need to add some users first using ‘Add New User’ link.

add.php file is responsible to add new users. HTML Form is used to capture user data. After User data is submitted, MySQL INSERT Query is used to insert user data into database. You can “View User” after user added.

edit.php is used to edit/update user data once user click on’Edit’ link. It first fetch user’s current data in form. You can change user data and update it. It will redirect to homepage, after successful update.

delete.php file simply called when we click on ‘Delete’ link for any user. It will delete selected user. Delete/edit/update operations user particular user_id to identify users.

Common Mistakes while running CRUD Script

  • Make sure you properly downloaded and extracted all files
  • Make sure you have created database properly with the same as as mentioned in config.php
  • When running CRUD script, make sure folder name is right. Sometimes there are folder inside folders. Adjust your path or folder accordingly.
  • For any other problem, you can send your error screenshot to tutorialsclass.online@gmail.com or contact us at facebook page

We will update next version of the CRUD script with basic validation functions. See you back.

PHP Simple CRUD Application Script Zip Download:

Download

PHP simple Login & Remember me script using Cookies

PHP simple Login & Remember me script using Cookies Zip:

Download

In this tutorials, we will learn how to create PHP Login & Remember me functionality using Cookies.

Code Description:

  • Create a simple PHP Form with username (text field), password (password field), remember (checkbox) & Login (submit) button.
  • If user select ‘remember’ functionality, save username & password in cookies
  • When Login Form loads, show recently saved username & password from the cookies
  • If user do not select ‘remember’, cookies will be deleted

Solution:

PHP Cookies are used to store small amount of information on browser than can be used later for different purposes. We will use PHP Cookies to remember user details. You can find HTML form code in page1.php & set/delete cookies on page2.php

1) We will create a form with username & password fields. User can fill details & click on login/submit button. After login/submission, form data will be passed/redirected to another page (page2.php). This form will show recent username/password automatically, if user has clicked remember me before.

Here is the code of page1.php:

2) This page will save username/password data in cookies if remember box is checked. If remember box is not checked, cookies will be cleared/deleted. You can check login page again to verify if cookies are saved or not.

Here is the code of page2.php.


Result: If user checked remember me, user details will be automatically loaded in form fields next time. That means that now your browser remember your username & password.
If user unchecked remember me, cookies will be deleted and browser does not remember user details. That means that form fields will be empty and user has to enter his username/password again.


How to use run above code script:

You can copy code from first box into a page1.php and code from second box into page2.php. Now you can test this code by entering user detail along with remember me checkbox or without remember me checkbox.

This is a very simple and easy PHP script to test PHP Cookies with Login form. You can simply download script and run on your computer as well.

PHP simple Login & Remember me script using Cookies Zip:

Download

Basic HTML Page layout using table tag

A webpage layout is often divided into multiple columns. Then these columns are treated as different sections of data. There are two most popular ways to create those columns in html page. One way is using <div> tag and another way is using HTML <table> tag.

Most of the website layout has one common header area where we place website logo or tagline (sometimes menu as well). Then we have main content section divided into two or three columns. Bottom of the webpage contains a common footer section, where we can place logo, copyright statement, menu or some other content.

In two columns we have one left or right sidebar area and one content area. In three columns page design, we have left sidebar area, main content area and then one right sidebar area.


Creating a HTML page layout using table tags

Let us create a two column layout along with header and footer area using HTML table.


Basic HTML Page layout using Div tags

A webpage layout is made of multiple columns. These columns are treated as different sections of data. There are two most popular ways to create those columns in html page. One way is using <div> tag and another way is using HTML <table> tag.

Most of the website layout has one common header area where we place website logo or tagline (sometimes menu as well). Then we have main content section divided into two or three columns. Bottom of the webpage contains a common footer section, where we can place logo, copyright statement, menu or some other content.

In two columns we have one left or right sidebar area and one content area. In three columns page design, we have left sidebar area, main content area and then one right sidebar area.


Creating a HTML page layout using DIV tags

Let us create a two column layout along with header and footer area using DIV tags.


HTML Contact Form Template

Create a Contact Form using HTML and CSS:

Many website use HTML Form to get input from the users. In HTML Language, we can create different kind of forms using various input fields. Most commonly used form elements are Text, Password, Number, Radio, Checkboxes, Textarea, Dropdown, Calendar (Date), URL, Upload file, Submit, Reset, and many more.

In this HTML Contact Form template, we have included all these fields. This HTML Form Layout is only made using Div tag along with internal CSS. We have used the minimum code for better understanding and there is no use of table tag.

Download

HTML Contact Form Template/Code:


Download HTML Contact Form Code:

You can download HTML contact form code using HTML/CSS with Div tag (without Table) tag.

Download

Redirect http to https using .htaccess in Apache

As per Google recommendation, it is good to secure your website with an SSL Certificate. It not only creates trust for users but also serves as a primary SEO factor.

Once you implemented SSL, you may want to redirect all web traffic from ‘http’ to ‘https’ using a .htaccess configuration file in the Apache web server.


Code to redirect all links from ‘http’ to ‘https’:

You can create a new ‘.htaccess’ file if it is not there in the website root. If it is already there, you need to put the following code in ‘.htaccess’ file. If it does not work with the existing code, you can try placing it in the beginning of the existing code.


Explanation:

  • <IfModule> is Apache directive that check if mod_rewrite module is loaded.
  • RewriteEngine OnEnables runtime rewriting engine.
  • RewriteCond %{SERVER_PORT} 80 restrict the rewrites to requests on port 80./li>
  • RewriteRule creates a rule to rewrite one URL to another.
  • [R=301,L] – Here, R=301 force 301 (permanent) redirects.
  • [R=301,L] – Here, L means “last rule” to stop further rules processing if this rule matched.

SEO Recommends 301:
If you are permanently redirecting URLs, you should use 301 redirects to maintain SEO, else 302 can be used for temporary URL redirects.

Note: If redirection code does not work, try placing code in the beginning of .htaccess file.


PHP Simple Login and Registration Script

PHP Simple Login and Registration Script:

Download

What is PHP Login and Registration Script?

This is a simple login and registration script based on PHP & MySQL. This script uses PHP session to store user details across multiple PHP pages to verify if the user is logged in or not. This script has minimal HTML/PHP/MySQL code which is easy to understand.


How to run Login-Registration Script:

You can simply download this script as a zip file, extract and run on your machine.

Here are the quick steps to run this script:

  • Download this script into a separate folder
  • Import database.sql file in a database ‘register_login_db’
  • Now run this folder’s index.php file. You will find ‘login’ & ‘registration’ link on this page.
  • Register some users and try to login with them.
  • You will be able to access page-1.php and page-2.php content only after login.
  • You can logout/login many times to test it.

Understanding code in each file

PHP Login and Registration script includes HTML Forms, PHP Session code & interacts with MySQL database to access users data. You will find that most of the code is well managed in a separate file. Here is the list of files along with their purpose.

  • database.sql: This file contains a query to create table structure for the login-register script. You can either import this file or directly execute given queries in PHP-Myadmin or available database management tool.
  • register.php: This file have an HTML registration form where user can enter his name, email and password. If registration data is valid, it will give success, else it will throw error.
  • login.php: This file contains HTML login form where user can enter email and password. The Same page keep PHP code to check if given email/password is matched or not. If login is successful, it will redirect user to page-1 content.
  • db-config.php: This file contains PHP code to create a connection with MySQL database and table. Login & Registration page includes this file to interact with MySQL data.
  • page-1.php & page-2.php: These files contains sample content which are only accessible after login. If you try to access these pages without login, it will redirect you to login screen.
  • logout.php: This file is used to distroy user data in PHP Session. This means that user will be logged out and redirected to login page.

How PHP Login and Registration code works

Mostly PHP scripts use PHP session or cookies to remember user details for login. This script also uses PHP session to track user login across multiple PHP pages to verify if the user is logged in or not.

Here is the basic idea behind PHP login and registration functionality.

  • Firsly, registration form allow users insert user details in database.
  • Then, user login using his registered email and password. Now if email and password found in database, user login considered successful. After successful login, we will save user email in PHP session variable.
  • Now on each content page, we will check if user email is available in session variable or not. If available, user can view content pages else he will be redirected to login page.
  • If a user clicks on logout link, PHP session gets destroyed and user needs to login again to view content pages.
  • This is how Registration/Login works to protect certain pages/features only for authorized/logged-in users.

Common Mistakes while running Login and Registration Script

  • You need to download and extracted all files preferably in separate folder.
  • Make sure you have created database properly with the same as mentioned in db-config.php
  • When running login-registration script, make sure folder name is right. Sometimes there is folder inside folders. Adjust your path or folder accordingly.
  • Understand the overall data flow using comments in each file.
  • If you found any issue with the script, please send your error screenshot at our facebook page. We will try to assist you if our schedule permits.

This PHP Login & Registration code is also available in Gitlab: https://gitlab.com/tutorialsclass/php-simple-login-registration-script

Download Simple PHP Login and Registration Script as Zip and try:

Download