douou1891 2013-07-18 08:57
浏览 18
已采纳

搜索表单将“sku”添加到网址

I have a search form that refreshes the page when the submit button is hit with the table of results below. this works fine and the url is http://example.com/?txtKeyword=searchterm I want it to add &sku=123456789 to the end of the url I know to add the sku from my database I need to use this term $_GET[sku]. I have tried to add this to the form and I have been unsuccessful. Here is the form code:

<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME']?>">
  <table width="100%">
    <tr>
      <th>Search: (Keyword/SKU)
        <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>" size="40">
        <input class="alert button" type="submit" value="Search"></th>
    </tr>
  </table>
</form>

I think I need to add this line:

<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME']'&sku='$_GET["sku"]?>">

This does not work. I am not too sure, trying to learn PHP and I cannot seem to find the problem or a solution. Am I doing this wrong and what would I need to do to get this right?

  • 写回答

1条回答 默认 最新

  • drxyaox153896 2013-07-18 09:08
    关注

    It Depends if your script is looking for a $_POST['sku'] or $_GET['sku'] when you process it.

    If it is a POST then you add a new hidden <input>

    <input type="hidden" name="sku" value="XXXXX">
    

    adding it to the form action will only work if it looks for $_GET['sku']

    EDIT

    If you wish to echo something if its there but not if it isn't then do something like this.

    <?php echo !empty($_GET['sku']) ? '<input type="hidden" name="sku" value="'.$_GET['sku'].'">' : ""; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)