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

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

How to create a table in MySQL using NodeJs

Now i will create a table in mysql (phpmyadmin) using nodejs code .First create write this code for details of db . I am using notepad++ you can use any code editor like sublime.

var mysql = require(‘mysql‘); Loading module .

Before executing this code you must download and install the mysql module.To access a mysql database with nodejs you need mysql driver.How to download mysql module: – Go to cmd and type npm install mysql. This line will download and install mysql on your local computer.

First load module mysql using the require function of node js. There are many modules in nodejs url , https, http ,realdline ,formidable etc and all the modules can be load using require function .

Now if you will check your db students table would have been created .

See our other tutorials

Nodejs file system

Nodejs file system allows us to work with your computer system. To work with nodejs file system you need to specifiy ‘fs’ in require() method:

Some use of file system :– To create a file , To delete a file , To update a file, To rename a file . Save this file on your folder app.js

If you run this code in your browser, It will generate this file in your folder newFile.php 

Nodejs first program

To run nodejs in your localhost you must have to download nodejs from nodejs site /https://nodejs.org/  . You can perform nodejs codes in notepad++. Now copy this code and paste in notepad++ & how to run this code I will tell you.This first application name is myfile.js

Now go to C Drive and open users folders and save this code inside your name folder (What is your computer user name):- C:\users\dheeraj\myfirst.js Now as you can see here dheeraj is my computer name.

Now open command prompt from the same folder where you have saved this file using shift + right click Or See this image

Nodejs run project

just type node myfile.js  & hit enter button this command will start your local server and go to browser type: http://localhost:8000 It will give this output.

Nodejs program

You can change port name from here }).listen(8000);  Always give free port which is not in use .

JavaScript array

Using array we can store multiple values in a single javascript variable. The array is a special variable which can store more than one value lets see a small example .

Now three variables for three values but if we have 100 car brands then we have to write 100 variables for 100 values.  So to avoid this situation we use an array. Now see the syntax of the array.

Array elements are numbered and starts with zero

If you run this code your output would be SUZUKI Why ?? 0 , 1 ,2 This is indexing DUKATI is at 0 , YAMAHA is at 1 & SUZUKI is at 2

Output :-

JavaScript Arrays

Now see more example of array indexing

Ouput of code

How to use array value in html

using document.getElementByID().innerHTML we can print array value in html form or paragraph tag or div tag .

It will print Bebbo Randy & Webmi  .So below is output

JavaScript Arrays in html

How to change array elements

Changing array elements is very simple . Lets see one example

Ronic will replace student Woler as you can see the index of Woler is 1. Output of code

How to change elemets of array

How to append or extract elemetns from array

push() is used to append or add elemetns to your array

Output this code

How to append elements in array()

How to use loop in Array

Let see example of for loop

Output of this code

Lopping in array

Now see more example

Output of code

Javascript DOM selectors

In this tutorial you will learn about DOM selectors .

How to select DOM elements in javascript

Javascript is used to get or modify the value of the html elements on website or page .We can apply some effect on webpage like animation , hide or show data . But , these all things happen with help of DOM selectors. If you don’t know how to target HTML element then you cant perform these tasks .

How to select elements

Selecting DOM elements is essential part of javascript . If you have to perform any animation like progress bar that time you would need to use DOM elements . Now we will see some examples .

document.body.style.background = “green”; using this code we can change bg color of body & document.head.firstElementChild.nodeName; this code is used to target <head> elements as you can see there are two elements in HEAD Tag one meta and another is title .

Select HTML elements by id

You can select html element by its id document.elementByID()  so let see one example of it

Output of code

Selecting html element by its id

I am javascript

I am jquery & i am the best library of javascript

document.getElementById(“para1”); if no matching element found null will be returned & the value of attribute id should be unique in the page.

How to select element by class

Using getElementsByClassName() , we can also use class name for select element

Output of code

Select element by class

I am javascript

I am nodejs

I am angularjs

To color both attributes i used for loop using loop we can color thousands of lines .