Home > Backend Development > PHP Tutorial > Web Development N Examples - Case 3: Using post and get methods to pass parameters between php and html

Web Development N Examples - Case 3: Using post and get methods to pass parameters between php and html

WBOY
Release: 2016-08-08 09:29:34
Original
1009 people have browsed it

N examples of web development

Case 3: Use post and get methods to pass parameters between php and html

case3.php:

<!DOCTYPE html>
<html>
<head>
    <!-- 请将文档保存为UTF-8编码,否则中文会乱码 -->
    <meta charset="UTF-8">
    <title>案例3</title><!-- 使用post和get方法在php和html间传递参数 -->
</head>

<body>

<!-- 使用get方法传递 -->
<form action="case3-output.php" method="get">
    get提交的数据:<input type="text" name="getText">
    <input type="hidden" name="getHidText" value="get隐藏文字">
    <input type="submit" name="g_sb"><!--提交按钮,只有提交了才能够传递表单参数-->
</form>

<!-- 通过url直接传递,也属于get方法 -->
<a href="case3-output.php?urlText=传递文字">点击超链接传递参数</a>

<!-- 使用post方法传递 -->
<form action="case3-output.php" method="post">
    post提交的数据:<input type="text" name="postText" >
    <input type="hidden" name="postHidText" value="post隐藏文字">
    <input type="submit" name="p_sb"><!--提交按钮,只有提交了才能够传递表单参数-->
</form>

</body>

</html>
Copy after login

case3-output.php:

<?php
if(isset($_GET["getText"]))
    echo "get传递的数据为:{$_GET[&#39;getText&#39;]}<br>";
else
    echo "没有通过get传递数据<br>";

if(isset($_GET["getHidText"]))
    echo "get传递的隐藏数据为:{$_GET['getHidText']}<br>";
else
    echo "没有通过get传递隐藏数据<br>";

if(isset($_GET["urlText"]))
    echo "url传递的数据为:{$_GET['urlText']}<br>";
else
    echo "没有通过url传递数据<br>";

if(isset($_POST["postText"]))
    echo "post传递的数据为:{$_POST['postText']}<br>";
else
    echo "没有通过post传递数据<br>";

if(isset($_POST["postHidText"]))
    echo "post传递的隐藏数据为:{$_POST['postHidText']}<br>";
else
    echo "没有通过post传递隐藏数据<br>";
Copy after login

Very commented It’s detailed and no further explanation is needed.

The above has introduced N examples of web development - Case 3: using the post and get methods to pass parameters between php and html, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template