Crud operations in PHP using mysqli and PHPMyAdmin

PHP MySQL CRUD involves the connection of PHP with the MySQL database and performing Create (Insert), Read (Select), Update (Modify), and Delete Operation on the table. PHP and MySQL connectivity is a very important topic while learning PHP here step by step PHP and MySQL connectivity and creat update delete and read operations are discussed using … Read more

Polymorphism in PHP with Example

Polymorphism in PHP is one of the important concept in OOPs. Polymorphism is a Greek word. Polymorphism is created by two different words poly (means many) and morph (means forms). It is another functionality of OOPS. In programming language two types of Polymorphism are there. Function overriding (Run time Polymorphism) Function Overloading(Compile time Polymorphism) Function … Read more

How to remove special characters from string in PHP

Characters other than alphabet [A-Za-z] and digits [0-9] are known as special characters like symbols & ^ % @. Removing special characters from PHP string is very easy by using php library functions like preg_replace() str_replace() Lets see them one by one Using preg_replace() to remove special characters from string in PHP PHP provides preg_replace() … Read more

PHP String

String means set of characters or letters or combination in single or double quotes. Like ‘PHP Language’. If you placed the number in the single quote or double quotes it’s also a string. Like ‘12345’. Similarly, special characters symbol whatever if you write it in the single or double quote it’s become a string. In … Read more

String functions in PHP- uses and examples

Now list some String functions in PHP to handle and manipulate string in PHP. All functions explained are inbuilt PHP functions also known as predefined string functions in PHP. These functions are defined during creation of PHP. sterlen() Length of String sterlen() function is used to get the entire length of the string. If there … Read more

PHP while loop syntax and example

While loop in PHP is also used for repeating statements in PHP. PHP while loop check for condition if condition is true then code inside body of loop is get executed. while – As long conditions is true, it loop back again and again through block of code. Syntax:while (condition is true) {code to be … Read more

PHP Form Handling with Examples

PHP Form method is used to sending data from browser to server.

Two types of methods are there GET and POST.

$_GET and $_POST are used to receive value from the form method.

$_GET and $_POST are the global variables so declare it with uppercase otherwise this will not work.

Syntax of GET Method in PHP:


Syntax of POST Method in PHP:


Note: by default form method is get.

If any user does not declare method attribute in the form tag then value send by getting method automatically.

If any users declare form method attribute value post and receive value in the server using $_GET variable then it does not work same as vice versa.

Get and Post method both are same and used for the same purpose but there has some difference.

Html/Text Response from PHP

Sending any kind of data from the form all go as a string type.

Program: PHP Program to submit user details in PHP form and show in PHP HTML table format.


User Form in php
User Form
User Form in PHP
User Response

Send JSON Response from PHP Form

JSON is another way to use for exchange data format between web client and server.

Enabling HTML forms to submit JSON directly simplifies implementation as it enables backend services to operate by accepting a single input format that is what’s more able to encode richer structure than other form encodings (where the structure has traditional had to be emulated).

Form’s type attribute value set application/ json to transmit JSON data from the form.

Example: Form submit in php to send user details and get PHP JSON response.


PHP Form to enter user details

By default input type is text.

Value send from the form by method and json_encode is a function which exchanges PHP server data into JSON format.

Example: How to Upload an Image in PHP


File Upload Example in PHP
Uploaded file detail in PHP

Upload any kind of file through form need set enctype attribute value with multipart/form-data. It means multi-type file can upload from Form.

Next always use post method in form because get method only sends 1kb data.

Next file value receives always in the server via $_FILES[] global array whatever form method in form, Which has 5 parameters name size type tmp_name and error.

Name index return name value of the uploaded file.
Size index returns size value of the uploaded file in bytes.

Type index return uploaded file type value like image/jpg for jpg extension file, application/pdf for pdf file, application/docx for document file, plain/text for text file etc.

Tmp_name index returns the uploaded file location. In server, there has a tmp folder initially where all the uploaded files are stored temporarily.

Error index return by default 0 otherwise if the size or any other index value return any error then error index return 1 or 2

Want Upload pdf file then only change the condition of above example

Example: How to Download a File in PHP

Provide file name to download,set its content type.

on calling url it will get downloaded.

PHP File Upload Example

PHP File Upload is a very important topic in PHP. Build any kind of websites or web application there has must be files. So want know that how can upload files or retrieve those files and download it (if required). You should have basic knowledge of Form Handling in PHP for working uploading a file. … Read more

PHP for and foreach loop statement

It is used when one knows how many time one need to run the particular loop. It is also of two types: 1. PHP for loop statement Loop back again and again through specified time duration. PHP for loop syntax:

Example: PHP for loop example

Result: The number is: 0The number is: 1The … Read more