PHP搜索HTML表单变量名称显示在Web URL上

时间:2019-04-20 20:02:58

标签: php

我正在创建PHP搜索表单,我想在URL上显示搜索变量名称,像这样的http://localhost/zblog/results/1/我想得到这样的URL

http://localhost/zblog/results/1/xxcxcxc

这是我的代码

<?php  
$search = $_POST["search"];
?>
<form action="<?php echo $url; ?>results/1/<?php echo $search; ?>" method="post" name="search" id="searchthis" style="display:inline;">
<input id="search-box" name="search" size="40" type="text" placeholder="what are you looking for............"/>     
<input id="search-btn" value="search" type="submit"/>
</form>

1 个答案:

答案 0 :(得分:0)

您需要将表单方法更改为method =“ get”,并检查$ search获得正确的值。

<?php  
$search = $_GET["search"];
?>
<form action="<?php echo $url; ?>results/1/<?php echo $search; ?>" method="get" name="search" id="searchthis" style="display:inline;">
<input id="search-box" name="search" size="40" type="text" placeholder="what are you looking for............"/>     
<input id="search-btn" value="search" type="submit"/>
</form>