How to get input value in PHP

0 votes

I have a input field as follows:

<input type="text" name="subject" id="subject" value="Car Loan">

I would like to get the input fields value Car Loan and assign it to a session. How do I do this using PHP or jQuery?

Nov 20, 2020 in PHP by kartik
• 37,520 points

edited Feb 12 by Sunita 77,049 views

1 answer to this question.

0 votes

Hello,

Use PHP's $_POST or $_GET superglobals to retrieve the value of the input tag via the name of the HTML tag.

For Example, change the method in your form and then echo out the value by the name of the input:

Using $_GET method:

<form name="form" action="" method="get">
  <input type="text" name="subject" id="subject" value="Car Loan">
</form>

To show the value:

<?php echo $_GET['subject']; ?>

Using $_POST method:

<form name="form" action="" method="post">
  <input type="text" name="subject" id="subject" value="Car Loan">
</form>

To show the value:

<?php echo $_POST['subject']; ?>
answered Nov 20, 2020 by Niroj
• 82,800 points

Related Questions In PHP

0 votes
1 answer

How to Get the full URL in PHP?

Hello @kartik, Have a look at $_SERVER['REQUEST_URI'], i.e. $actual_link = ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,800 points
3,932 views
0 votes
1 answer

How to delete element by value in array (not key) using php?

Hello @kartik, Using array_search() and unset, try the following: if (($key = ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,800 points
2,602 views
0 votes
1 answer

How to GET URL parameter in PHP?

Hello @kartik, $_GET is not a function or language ...READ MORE

answered Sep 17, 2020 in PHP by Niroj
• 82,800 points
4,410 views