如何在php中通过更改url中的参数并按enter键来搜索结果

如何在php中通过更改url中的参数并按enter键来搜索结果,php,mysql,Php,Mysql,我想通过更改参数值并在地址中按enter键来搜索结果。 当我在主页上搜索时,我使用此表单在url中传递搜索关键字 eg:->http://localhost/mydeals/searchListing.php?sRes=g 现在,当我在searchListing.php上时,我想将sRes的参数更改为p,就像这样,然后当我在地址栏中按enter键时,我会得到$u get中的值,所以我如何搜索它 eg:->http://localhost/mydeals/searchListing.

我想通过更改参数值并在地址中按enter键来搜索结果。 当我在主页上搜索时,我使用此表单在url中传递搜索关键字

eg:->http://localhost/mydeals/searchListing.php?sRes=g
现在,当我在searchListing.php上时,我想将sRes的参数更改为p,就像这样,然后当我在地址栏中按enter键时,我会得到$u get中的值,所以我如何搜索它

eg:->http://localhost/mydeals/searchListing.php?sRes=p
我在配置文件中编写的php代码是

if(isset($_POST['search2']))
    {
        if(trim($_POST['location2'])!="" && $_GET['sRes'] =="")
        {
            $_SESSION['dirLocation2'] = trim($_POST['location2']);
            header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
        }else if($_GET['sRes'] !=""){
            $_SESSION['dirLocation2'] = trim($_GET['sRes']);
            header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
        }else{
            header("location:".THIS_DOMAIN."index.php");    
         }
    }

    if (empty($_GET["sRes"])) {
        header("location:".THIS_DOMAIN."index.php");    
    } else{
        $_SESSION['dirLocation2'] = trim($_GET['sRes']);
            header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
    }

您可以通过检查url参数来做到这一点,如

<?php

if (empty($_GET["sRes"])) {
    header("Location: index.php");
} else {
    $sResValue = $_GET["sRes"]; // p, or s
    // Do your search here
}

您的问题与代码无关。你的实际问题是什么?你想做什么?我试图通过更改我在url$\u POST['search2'中传递的参数来搜索reasult是我在主页上搜索的Button的名称页面重定向不正确Fireox检测到服务器正在以一种永远不会完成的方式重定向对此地址的请求。存在重定向循环。你能在你的问题中给出准确的代码吗?我需要查看您的整个代码,以避免出现重定向循环,您是如何测试它的?让我们来看看
if(isset($_POST['search2']))
    {
        if(trim($_POST['location2'])!="")
        {
            $_SESSION['dirLocation2'] = trim($_POST['location2']);
        header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
        }
        else{
            header("location:".THIS_DOMAIN."index.php");    
         }
    }

if (empty($_GET["sRes"])) {

} else{
        $_SESSION['dirLocation2'] = trim($_GET['sRes']);
}