3

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

Ram Singh
  • 6,664
  • 35
  • 100
  • 166
  • Try $_POST['firstname'] or $_GET['firstname'] for POST and GET queries respectively. – John Reid Nov 04 '15 at 09:23
  • 1
    @JohnReid It's a query string. That is never going to end up in the `$_POST` superglobal – PeeHaa Nov 04 '15 at 09:24
  • No, but as he has said he's new (and using ajax) I'm explaining how to get at both. You're right though - $_GET will retrieve the querystring items. – John Reid Nov 04 '15 at 09:25

2 Answers2

3

You are looking for the $_GET superglobal

$_GET['firstname']
$_GET['lastname']
danjam
  • 1,064
  • 9
  • 13
1

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

$_GET['firstname']
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335