How To Retrieve Input data From Input Field

Welcome to liveiplmatch.com, a huge request to make a post that How To Retrieve Input Data From The Input Field with the help of PHP.

PHP is a dynamic programming language, which can help you to create dynamic pages on your website.

There are two methods available in the form tag one is GET and another is POST.

You use two method to retrieve user input from the html form.

First of all we create a form

<form action="" method="">

</form>

Action is used to send data after submitting means if we want to send users to another page after submit then we use the action parameter.

Method is used to take the data from user by GET and POST.

If we use the GET method then all the data will be pass the page url which the user can see the data and modify it.

POST is used to send data without passing url.

<form action="welcome.php" method="GET">
	
</form>

For POST

<form action="welcome.php" method="POST">
	
</form>

Above code will be send to welcome.php page after submission of the form.

The we use input method to take input from user

Lets start the step …

In this tutorial we are going to take username and password, to achieve this we use two input tags one for username and another for a password.

<input type="text" name="username" placeholder="Input Username">
<input type="password" name="password" placeholder="Input password">

We take another input for submit button.

<input type="submit" name="submit" value="Submit">

Final output of our form will be look like this

<form action="welcome.php" method="">
<input type="text" name="username" placeholder="Input Username">
<input type="password" name="password" placeholder="Input password">
<input type="submit" name="submit" value="Submit">
</form>

Lests start our php code , remember one thing that PHP code put alawys top of the page

1st check if submit button is checked or not

isset($_GET['submit']) : for get method
isset($_POST['submit']) :  for post method

To check submit is clicked or not we use it in a if block

if (isset($_GET['submit'])) {
   //all code here
}

Now create variable for store the input data

if (isset($_GET['submit'])) {
	$username = $_GET['username'];
	$password = $_GET['password'];
}

Now you get the data by the variable $username and $password

If you want to show the input just echo the variable.

echo 'Username Is : '.$username.'<br>';
echo 'Password Is : '.$password.'<br>';
	

So the final code looks like this

<?php
if (isset($_GET['submit'])) {
	$username = $_GET['username'];
	$password = $_GET['password'];
	echo 'Username Is : '.$username.'<br>';
	echo 'Password Is : '.$password.'<br>';

}
?>

<form action="welcome.php" method="">
<input type="text" name="username" placeholder="Input Username">
<input type="password" name="password" placeholder="Input password">
<input type="submit" name="submit" value="Submit">
</form>

If you have any doubt then comment below

Thanks

Liveipl2021

leave a comment

Create Account



Log In Your Account