search
Homephp教程php手册php接收表单提交数据实例详解

在php中表单提交数据有几种,一种是post和get方式,下面我来给各位php初学者详细介绍利用get,post来接收表单提交数据实例用法,有需要了解的朋友可参考.

PHP $_GET 和 $_POST变量是用来获取表单中的信息的,比如用户输入的信息PHP4.1(好像)以后取消了直接接收变量,而用 $_GET['变量名'] 接收从链接传递过来的变量, 用 $_POST['变量名'] 接收从表单提交来的变量.同样有$_FILES[],$_SERVER[]等

下面是一个 HTML 文件,这个 HTML 含有一个 HTML 表单 (HTML Form),主要用来让用户输入用户姓名的.

实例代码如下:

<form action ="get.php" method ="get">Name:  
<input type="text" name="username" /> 
<input type ="submit" value="ok" /> 
</form>

该 HTML 的显示界面如下:

当你在这个 HTML 文件的表单文本框输入框里输入姓名,比如 "Jacky",然后鼠标点击ok 按钮,会跳转到 get.php,在 get.php 里会显示如下图.

get.php 的源代码如下:

实例代码如下:

<?php echo $_GET["username"];?>

取表单控件的 name 值,可以获得该表单控件的数据.比如 "username" 就是表单控件文本输入框的 name 值。

实例代码如下:

<input>

用 $_GET["username"] 可以获得该文本输入框的数据.

实例代码如下:

<?php echo $_GET["username"];?>

获取 HTML 表单 (HTML Form) 单选框 (input type="radio") 数据,取表单单选框的 name 值,可以获得表单单选框的值.$_POST获取HTML表单提交数据.

下面是一个 HTML 文件,这个 HTML 含有一个 HTML Form,主要用来让用户输入用户姓名的.

实例代码如下:

<form action ="post.php" method ="post"> 
Name: <input type="text" name="username" /> 
<input type ="submit" value="ok" /> 
</form>

当你在这个 HTML Form 的文本框输入框里输入姓名,比如 "Jacky",然后鼠标点击ok 按钮,会跳转到 post.php,显示的输出结果是You are Jacky..post.php 的源代码如下:

实例代码如下:

You are <?php echo $_POST["username"];?>

取表单控件的 name 值,可以获得该表单控件的数据.比如 "username" 就是表单控件文本输入框的 name 值,

实例代码如下:

<input>

用 $_POST["username"] 可以获得该文本输入框的数据.

实例代码如下:

<?php echo $_POST["username"];?>

$_REQUEST变量

PHP $_REQUEST变量包含$_GET, $_POST, and $_COOKIE的内容,PHP $_REQUEST变量可以用来获取通过"GET"和"POST"这两种方法发送的表单数据.

实例代码如下:

Welcome <?php echo $_REQUEST["name"];?> .<br /> 
You are <?php echo $_REQUEST["age"];?>  years old

 

文章网址:

随意转载^^但请附上教程地址。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool