Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get multiple Query String values from URL? [duplicate]

I am very newbie in PHP, i am passing query string to a ajax call using the below code. i want to get these on another php page. but not getting how i can get these:

$("#saveForm").click(function(e){
var test =$("#Field4").val();
alert(test);
$.ajax({
   url: 'mytest.php?firstname=ram&lastname=Singh',
   async: false,
   success: function (response) {
        alert(response);
   }
  });
});

i have tried the code as below to get query string, but it is giving me all query strings in one string

$name = $_SERVER["QUERY_STRING"];
echo($name);

i have some expewrince in ASP.NET. and in ASP.net we can get the value of query string with it's key like, if we want to get firstname from the query string we use as below:

string fName= Request.QueryString["furstname"];

can we do the same in PHP, if it is possible then, how? i have checked on google alot but not found any helpful link. Please help me

like image 785
Ram Singh Avatar asked Jul 02 '26 20:07

Ram Singh


2 Answers

You are looking for the $_GET superglobal

$_GET['firstname']
$_GET['lastname']
like image 63
danjam Avatar answered Jul 05 '26 13:07

danjam


PHP parses query string variables into an associative array stored in the superglobal $_GET

$_GET['firstname']
like image 27
Quentin Avatar answered Jul 05 '26 11:07

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!