Web Development -

CRUD Operation in PHP-PDO

Today i am giving you toturial on PDO-PHP .Here i will creat full CRUD system in PDO using PHP. So below is your connection in PDO so see carefully it looks tought but dont worry it is very easy compare to Mysqli. I didnt give file name here it is upto you what name you want to give. Just remember the syntax ”bindparam” is used for bind your data and colon ( : ) is uesd for SQL INJECTION prevention

Always use try & catch block for pdo connection and if you dont use try-catch then you cant cathc your error . For source code comment your mail

I have used PHP include_once function to connect database connection to all files but you can write DB connection in each file but good practise is use connection file separately and connect it with help of require_once or inlcude_once.

Now this is screen short of your add form page

Now this is your form code

This code will use for insert your data in table using PDO Method

Now i am putting code of index file ,Below is your index.php file or you can say main page of your small project

We can use query or execute statement method in PDO but exceute is more safer than query against Sql Injection

query runs a standard SQL statement and requires you to properly escape all data to avoid SQL Injections and other issues.

execute runs a prepared statement which allows you to bind parameters to avoid the need to escape or quote the parameters. execute will also perform better if you are repeating a query multiple times. Example of prepared statements:


So i have given you two examples how to write query and excecute method in PDO

This is screenshort of your index.php

Now i will put code of edit.php

Now this is final code block which your delete.php

This way you can do CRUD Operation in PHP-PDO.

Check these tutorials in php

Search Filter in PHP MYSQL

CRUD Operation with Search Filter Feature

I will show you a full code of CRUD operation with a search filter option. I have used Core PHP for backend and Javascript, CSS and Html for Front-end. I didn’t have used ajax call for sending and receiving requests.

First see the database of this project

id , city and country only 3 coloumns . Now connection code


Project Screen Short –

I have divided code into 10 pages Header , footer and source code .

Now I will start from the add.php page it has designing and coding part as well.

I have called the connection of database using require() function of PHP. You can use either include() or include_once() or require() according to your requirements.I am using CDN link to enable Bootstrap functionalities into your code.

Now we will see an index.php page which is your the main page and you have seen this page in the first screen short.


Now we will see header.php , footer.php , edit.php and delete.php .


The header page has all cdn links of Boostrap and Jquery.


Now we will see update and delete page .


Now will see delete.php page


Now lets see search filter option.


Finally will see style.css .


How to color background of last inserted row in PHP

Without last_insert_id

I have colored background of last inserted row without using last_insert_id. You can do this by using LIMIT and ORDER BY of MySQL.

Php insert id , php last_insert_id

Database Structure :

id , name , address , gender , designation ,age

Now lets start with our code ,First make this databse table in your database.

In this way you can color the background of last inserted row in php

See our more articles on PHP and JAVASCRIPT

How to make sales receipt in PHP

Pagination in php

Show data from using Drop Down list in PHP

How to show data from Database using drop-down PHP

We can show database value in a table using the dropdown list. Below is a database structure. You can add more data to the database.

Database Structure


Now we will see code for dropdown list

This is way we can show data in a table using drop down.

OutPut of the code :

See our more articles on PHP, JAVASCRIPT and JQUERY

How to make sales receipt in PHP

Sales print in php

It’s very easy to make a sale receipt like Amazon in PHP. I am only fetching data from the database so I have used myself. The database Columns name would be – id, name, price, qty (int, varchar, int, int ).

I have multiplied Price into Quantity to get Total Price. Price * Quantity = Total Price.

See More tutorials on PHP and JAVASCRIPT .

Shopping cart in PHP

Shopping cart in PHP

How to make Shopping cart in Core php

I didn’t have used any PHP framework. This shopping cart in core PHP and it is only for beginners. You will see Add to cart, Add to a product, delete a product, preview product, log in, and log-out. I have written a design code on a different page and business logic code on a different page.


If you run this project in your browser you will see this output. For source code please leave your mail in the comment box.

This is your project structure in your folder. As I said Business logic and design code both have written on different pages.

Now start with a database this is the database design. There are two tables and a total of 9 columns. Save table is used for Registration and Login.

Now I will show you the complete code of connection as know that without connection can’t complete this project.

Save this code as connection.php

Now we will see Sign up page code and login page code. Now see registration.php This page only has designing part and business logic will be on a different page with the name registration_action.php


Now you will see business logic of registration page.


The extract() Function is an inbuilt function in PHP. The extract() function does array to variable conversion.

Now we will see login page but first, we will see design page of login then business logic.

index.php (Design page of Login Form)

Now we will see business logic of Login form index login_action.php

This is our logout page logout.php

error_reporting(0) is used to avoid warning and notice. Now the next step is to add header and footer page. I didn’t add any menu in the header but there is a menu in the footer but the footer menu is empty.



Now we will see the code of home page which showing four data in the front end. You can add more products but I am showing just four product on each row.


Now we will see how to add product in main page . There are total 8 coulumns.

This is designing page of add_product page add_product.php

Now see business logic of add_product page product_action.php

How to see product in diffrent page or on model box . view_detail.php

Now, this is our last code of the project, how to remove a product from the main page. empty_cart.php

If you want source code of this project please drop your mail in the comment box.

Multidimensional Array in PHP

Output of the code :

Name #1:Name :Learn PHP from java2s.com 
City :Mumbai 
Year :1999 
Name #2:Name :Learn Java from java2s.com 
City :Nagpur 
Year :1823 
Name #3:Name :Learn HTML from java2s.com 
City :Vasai 
Year :1992 
Name #4:Name :Learn CSS from java2s.com 
City :Nalasopara 
Year :2011 

See more Tutorials on PHP

How to insert checkbox value in multiple rows

This is just an example and just try to unserstand flow of the code .

$chk_id = $chk_box [$i]; This will store id or searial number of each line 1, 2,3,4….so on

Pagination in php

I will show how to do pagination in php

Output of the code :

Check out these tutorials

How to handle JavaScript DOM elements

How to manipulate HTML elements using javascript code

First we have to find html elements.To achieve this we have several ways

Find html element by id , Find html element by class name ,Find html element by css selectors , Find html element by tag.

Work with html element id

By using element id we can find elements in the DOM.

Output of code

Get element by id

I am javascript

How to find HTML element by tag

Tag means like div tag , p tag and other different tags in the html. Now we will target these tags using javascript code.

Output of code

Element by tag

I am javascript

Jquery is a library of javascript

Foreach loop in php

How to use for each loop

loops through a block of code foreach() element in an array. The foreach() loop is specially used for array .

Output of code

Name :- Dheeraj Singh
Email :- [email protected]
Phone :- 22393933
Address :- Mumbai
State :- Maharastra

Lets see another example of foreach loop

Output of code

Print Number is 100 
Print Number is 200 
Print Number is 300 
Print Number is 400 
Print Number is 500 
Print Number is 600 
Print Number is 700 
Print Number is 800

See our more tutorials on web development