nsds
nsds

Reputation: 981

Can we POST values coming from url

I want to POST values coming from a url .

My url is xxx.com/aa.php?name=RAM

On aa.php page I have written like this

<?php $NAME=$_POST["name"]; ?>

but its value is getting null .

but when using GET Method its values is getting as 'RAM'.

How can I retrieve values using POST from a url ? or is it not possible?

Upvotes: 0

Views: 88

Answers (5)

Priyank
Priyank

Reputation: 3868

if you are not sure about your method i.e. $_GET or $_POST.you should use $_REQUEST. $NAME=$_REQUEST["name"];

for more information:http://www.tutorialspoint.com/php/php_get_post.htm

Upvotes: 0

john
john

Reputation: 567

The only solution to pass the data with hidden method is either you should use curl or using form submission with post method like

<form name="" action="aa.php" method="post">
<input typ="hidden" name="name" value="RAM">
<input type="submit" name="submit" value="submit">
</form>

then you can get this as 

$_POST['name'] 
on aa.php page

Upvotes: 0

Jite
Jite

Reputation: 5847

When the parameter is in the URL it is a GET parameter.
You can not fetch a GET parameter from the $_POST array, but the $_GET array.
You can also use the $_REQUEST Array to get both POST and GET variables.

In your case, the GET variable with the key name is RAM, as it should be.


edit:
Worth to mention is that the $_REQUEST array pretty much is a concatenation of $_POST, $_GET and $_COOKIE, so it might behave unexpected if any of the others (than the one you are after) are using the same key names.
I would recommend using the type you are actually wanting, in this case, the $_GET list.

Upvotes: 0

Ram Sharma
Ram Sharma

Reputation: 8809

If you are not sure about $_GET & $_POST method then you can try $_REQUEST also.

$NAME=$_GET["name"];  //work in get method

$NAME=$_POST["name"]; //work in post method

$NAME=$_REQUEST["name"]; //work in both method

Upvotes: 1

Mad Angle
Mad Angle

Reputation: 2330

Use $_GET instead of $_POST

<?php $NAME=$_GET["name"]; ?> 

Upvotes: 1

Related Questions