php搜索html表单变量名称显示在web url上

问题描述 投票:-1回答:1

我正在创建PHP搜索表单我想在URL上显示搜索变量名称我的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>
php
1个回答
0
投票

你需要将form方法更改为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>
© www.soinside.com 2019 - 2024. All rights reserved.