Web Forms in PHP

HTML and PHP code is simple to embed into single document which makes easy to design static(HTML) and dynamic(PHP) pages together. A PHP interpreter will ignore everything outside PHP tags i.e. plain text/HTML code.
Plain text/HTML code is interpreted by the browser. By default characters like new-line(\n) , space(\s) are generally ignored by the PHP interpreter when printing on to the web page. These generic characters can be replaced with corresponding HTML tags

First PHP program

# Source Code
<html>
<head>
	<title>
		My PHP Page
	</title>
</head>
<body>
		<?php
			echo 'My First PHP Script';
		?>
	</body>
</html>
#Output
My First PHP Script

Working with forms

PHP is used for server side scripting, hence it is able to interact with any element placed within the HTML form. The GET or POST method can be used to send data from the form to the web server.

Capturing form data
1. $_GET: Auto populated when form is submitted with GET method
2. $_POST: Auto populated when form is submitted with POST method
3. $_REQUEST: Auto populated when form is submitted with either GET/POST method

Name of the form element will be key and user entered value will be the value of corresponding key

<?php
	$_GET['Pname']
	 
	$_POST['Pname']
	 
	$_REQUEST['Pname']
?>

GET method

In the GET method, information is embedded in the URL and hence not secure. Not suitable for sending large data. Not suitable for sending password information or sensitive data.

<html>
<body>
    <?php
       echo 'CONGRATULATIONS, Our new product.$_GET["Pname"].‘ is launched with a price of  Rs.'.$_GET["Price"]
     ?>
</body>
</html>

POST Method

Information is embedded in the body and not in the URL. Hence more secure compared to GET method. Data up to 8Mb can be sent using this method

REQUEST Method

Contains the contents of $_GET, $_POST, $_Cookie. Can be used when data is sent using either GET or POST method