PHP Archive

Day 2 – Some basic programs in PHP

Now let’s write and run some basic programs in PHP. Program 1: Program to print “Welcome to php” in PHP. Open notepad++ and write below lines of code: <?php echo “Welcome to php”; ?> Save this program in C://xampp/htdocs/welcome.php Note: if xampp is not installed in C:// then save your program which ever drive xampp

Day 1 – Introduction to PHP

PHP is server side scripting language to develop dynamic websites. PHP developed in 1995 by Rasmus Lerdorf. Early versions PHP was called Personal Home Page but it not seem to be a technical, so PHP rename “Hypertext Preprocessor”, or we can say “Personal Home Page Hypertext Preprocessor”. Advantages of PHP:- Its free. Open source. Easy

Database Connectivity in Php

This blog is going to explain how to connect database with php and display all the records of table. STEP 1: Create a table and insert some records in it. create table emp (id int, name varchar(50), salary int, phone varchar(20)); insert into emp values (1,’Albert’,56000,’98587485768′); insert into emp values (2,’Robart’,58000,’98587485768′); insert into emp values

The Global Keyword

A global variable can be accessed in any part of the program. In php global keyword is used to access a global variable. Global keyword has to use before the variables (inside the function). Global variables are stored in an array called $GLOBALS[index]. Index holds the name of variable and this array can directly access

Get Last Inserted Id

There are many cases where we need AUTO_INCREMENT ID that generated from the previous INSERT operation, we can get that by using mysql_insert_id() function. Like:- $con = mysql_connect(“localhost”, “root”, “”); mysql_select_db(“my_database”,$con); $query = ”insert into emp (name,salary,phone) values (‘amit’,9000,’9847476744’)”; mysql_query($query); echo “Last inserted id is ”. mysql_insert_id(); Some time programmer use “select max(id) from tablename”

Object Oriented PHP

The Major difference between PHP 4 and PHP 5 is, PHP 4 is not object oriented but PHP 5 is full object model. Some Features of Object Oriented Language:- Class: is a collection of member variables and functions. Object: is a instance of the class. We can define a class once and then make many

Calculate Age out of Date Of Birth

Generally we store date of birth in our database and in front end we have to display age also. In php we can use following code to calculate AGE out of date of birth. $dateofbirth = “12/08/1984”; echo floor((time() – strtotime($dateofbirth))/31556926); Any question please write in comments.

Change Date Format in php

How to change date format in php? we can display date in different formats in php as given:- $dt = “2001/02/02”; echo date(‘d M Y’, strtotime($dt)); Output:- 02 Feb 2001 $dt = “2001/02/02”; echo date(‘M d Y’, strtotime($dt)); Output:- Feb 02 2001

File Upload in PHP

<html> <body> <form action=”upload.php” enctype=”multipart/form-data” method=”post”> <input type=”file” name=”myFile” id=”myFile”><br> <input type=”submit” name=”submit” value=”Submit”> </form> <body> </html> Create another file “upload.php” that contains the code to uploading a file: <?php if(move_uploaded_file($_FILES[“myFile”][“tmp_name”],$_FILES[“myFile”][“name”])) { echo $_FILES[“file”][“name”].”Saved”; } else { echo “Unable To Save”; } ?> Other Parameters:- $_FILES[“file”][“type”] – to get file type. $_FILES[“file”][“size”] – to get

Submit Form without Submit Button

We can submit form on server with submit button by using Java script submit() function. like, if we want submit form on dropdown change, we can write a code:- <form> <select onchange=”this.form.submit()”> </form>