如何在get方法中显示最近的查询

时间:2015-09-21 17:58:17

标签: php getmethod

我有这个表格

<form action="" method="GET">
<label>NAME:</label>
<input type="text" name="name" id="name" required/>
<button>GET</button>
</form>

<?php

if (isset($_GET['name'])){

$name = $_GET['name'];

echo "hello".$name;}
?>

如果输入一个名称“google” 之后我再次进入“示例”

当我输入另一个名字时,有什么方法可以显示最近输入的名字吗?

1 个答案:

答案 0 :(得分:1)

我认为足以解决问题的代码将是

<?php
  if(!isset($_GET["name"]){
    print "the name parameter was not supplied";
    die();
  }
  session_start();
  $name = $_GET["name"];
  $_SESSION["list"][sizeof($_SESSION["list"])] = $name;
  var_dump($_SESSION["list"]);
  //I used var_dump here only to show the output you are free to use any other
  //way to display the data as you like