<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>get与post</title> </head> <body> <h3>GET传值</h3> <a href="?name=朱老师">点击这里进行get地址栏传值</a> <p> 这里输出值:<?php if(isset($_GET['name'])){ echo "地址栏传的值为---".$_GET['name']; }else{ echo "地址栏传还没有传值,点击上面的链接"; } ?> </p> <h3>post传值--一般是表单传值</h3> <p> <form action="#" method="post"> 姓名:<input type="text" name="username" value="<?php echo isset($_POST['username']) ? $_POST['username'] : "默认值"; ?>"> 昵称:<input type="text" name="nickname"> <button>提交表单</button> </form> </p> <p> 这里输出表单值: <?php if(isset($_POST['username']) or isset($_POST['nickname'])){ echo "姓名:".$_POST['username']." 昵称:".$_POST['nickname']; }else{ echo "先输入点内容"; } ?> </p> <p> 三元运算符: <?php echo isset($_POST['nickname']) ? $_POST['nickname'] : "这是三元运算符"; ?> </p> </body> </html>
点击 "运行实例" 按钮查看在线实例