如何使用PHP获取输入字段值

问题描述:

我有一个输入字段,如下所示:

I have a input field as follows:

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

我想获取输入字段值Car Loan并将其分配给会话.如何使用PHP或jQuery做到这一点?

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?

使用PHP的$_POST$_GET超全局变量通过HTML标记的名称检索输入标记的值.

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:

使用$_GET方法:

Using $_GET method:

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

显示值:

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

使用$_POST方法:

Using $_POST method:

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

显示值:

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