Using GET and POST for search function in PHP

I have a search box where the function is defined as follows:

if(isset($_POST['search']))
{
    $orgname= $_POST['search'];
......
}

POST search is carried out through the form. I was wondering if there is a way to make this function accept get through a link? For example, if I use the link as follows: mysite/page?search=valuecan I use $orgname=$_GET['search']functions to run without submitting the form? So there will be two methods for loading data from a function, one of which is submitting the form, and the other is by reference, as I mentioned above? Is it possible? I try to do this because I have another tab on this page where I have an update button where the user can submit the form after making changes to the form data. But after submitting the form, the update function works, but the page reloads and shows a blank form. I want to show updated data when this form is submitted.

+4
source share
2 answers

If you want to have the same behavior for both $_GET, and $_POSTyou can use a super galaxy $_REQUEST.

If you want to know where your data is coming from (ask for a GET or POST request), you can simply check for the presence of the parameter on both arrays:

if(isset($_GET['search'])
{
     //We have a GET request
}
else if(isset($_POST['search'])
{
     //We have a POST request
}
else
{
     //Nothing found
}
+2
source

You can use $ _ REQUEST

$_REQUEST - HTTP request variables

An associative array that by default contains content $_GET, $_POSTand $_COOKIE.

+2
source

All Articles