AllInOne -

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:

and

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 pdo connection and pdo registration

Check these tutorials in 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 .

Javascript inneHTML method

Javascript can display output in four different ways

Using innerHTML()
Using consol.log()
Using document.write()
Using window.alert()

To access users element we use innerHTML() .The id and class attributes define the HTML elements.

document.getElementById(“numberMult”).innerHTML this line will do multiplication & send output <p id=”numberMult”></p>

So output will be 129

Now lets see another example of innerHTML

You can concatenate javascript and html tags using + sign. Here i have concatenated html font tag with javascript variable with help of + sign .

Output of code

Javascript innerHTML Example

Lets see form example using innerHTML

Output of Code



We have called innerHTML inside a function and function called in onclick event of button.

See more tutorials web development

Javascript JSON parsing

Json is a text-based format like xml . JSON is easy to read and easy to understand for humans and computers but Json occupy less bandwith compare to xml . JSON is the most popular and lightweight data-interchange format for website applications. Below is json object.

We have seen Json object , Now below is Json array inside Json object

 

How to parse Json data in javascript

Lets suppose we have below data which we received from a server

Now we will use JSON.parse() method to convert this data into javascript object and access its value using dot symbol (.) See the below example

Output of code

Dheeraj
22222222
Jaipur

PHP Json data parsing

Json is a text-based format like xml . JSON is easy to read and easy to understand for humans and computers but Json occupy less bandwith compare to xml . JSON is the most popular and lightweight data-interchange format for website applications. Below is json object

JSON data structures are very similar to PHP arrays. Encoding and decoding of json data in php is very easy .PHP uses these two functions json_encode() and json_decode() for encoding and decoding of json data . Both functions only works with UTF-8 .

We have seen Json object , Now below is Json array inside Json object

How to encode Json data in php : – json_encode() function is uses to encode data to json format . The below example explanes how to use json_encode() in php for associative array .

Output of this code

{“Peter”:65,”Harry”:80,”John”:78,”Clark”:90}

How to decode Json data in php :-

Decoding json value is as simple as encoding .Now here we will use php json_decode() function convert the json encoded string to php data types

Output of code

9002020
23030030
78020292

See more tutorials on json & php

How to use chaining in Jquery

Jquery chaining allows us to run multiple methods togther .Simple chaining example :-

Now as you can see there is three methods css() , slideUp() & slideDown() and we can bind them together with help of Jquery chaining . You can also write this way . You can download Jquery from here www.jquery.com

Now i will show you complete example of chaining

Now run this code on your broswer Output :-

Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industrys standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book It has survived not only five centuries

See more examples of Jquery  

How to use json data using php

Json is javascript object notation . It used for data exchange on server . Json is light weight data exchange format which is useful for server & website communication .

Take a real life example Suppose Website A in java and Website B is in PHP but if they want to communicate with each other or wants to exchange data with each other then they will use Json or xml .

Json is very easy to use & language independent .Json is used to storing and transport data on server . Json is text format so it can be transported anywhere

XML is difficult to parse than JSON.
JSON is parsed into a ready-to-use JavaScript object. JSON can use array for multiple data

Different Json data types

a string , a number , boolean , an array , an object (JSON object)

this is json object and we can convert it to javascript object using JSON.parse();  We write json data or object withing curly braces { } .Json data must be in key and value format , both key and value separated by single colon .

A common use of Javascript object notation is to exchange data to/from a web server.

When receiving data from a server, the data is always a string form.

we parse the data using JSON.parse()&then data becomes javascript object

Now using php code we can convert to json

Output of code

{“name”:”dheeraj”,”age”:”37″,”state”:”haryan”} This is output is in JSON format & we got this output by using json_encode(); function of php

Lets see another example of json ( How to use loop in json)

Output of code

Using loop in json

Employee Job
Email
Cell Number

Now how to access its property through loop

Output of code :

Using loop in json

comupting
[email protected]
211882

How array works in json

Output of code

Chemistry

data = jObj.subjects[2]; I gave index 2 so output is chemistry

How to use get & post methods in Jquery

I am going to use get method, usually we work on get and post method so Jquery has two methods for sending data from browser to server & receiving data from server $ .get() & $.post() . We can also use these methods for AJAX REQUEST . The basic syntax of post & get method :

$.get(URL , data , success) ; This for get method

$post(URL , data , success); This is for post method

The URL specifies where to send data , data is used for string data & success is a callback function that executed if the request succeeds .

Below is php code for multiplication table : – table.php

If you run this code in your browser

See more tutorials on Jquery and php

How to do form validation in javascript

The validation part of javascript is very easy

This below code block is doing validation

if(name == “”) {
printError(“nameError”, “Please enter your name”);
} else {
var regex = /^[a-zA-Z\s]+$/;
if(regex.test(name) === false) {
printError(“nameError”, “Please enter a valid name”);
} else {
printError(“nameError”, “”);
nameError = false;
}
}

If you run this code in your broswer

 

 

 

 

Candidate Info Form

 
 
 
 
 

 

See PHP and JQUERY Tutorials

 

http://www.goolik.com/pdo-registration-in-php/
http://www.goolik.com/move-object-using-javascript/
http://www.goolik.com/how-to-use-accordion-in-jquery/
http://www.goolik.com/add-remove-class-using-jquery-ui/