Sangameshwar Kanugula
Sangameshwar Kanugula

Reputation: 25

Get form data for both POST and GET requests in PHP

I am unable to use a form with both POST and GET variables.

like, i want to access $_POST['sub1'] and $_GET['id'] in a php page.

Upvotes: 0

Views: 2353

Answers (3)

Progrock
Progrock

Reputation: 7485

This works for me:

<?php
$id   = $_GET['id']    ?? null;
$sub1 = $_POST['sub1'] ?? null;
var_dump($id, $sub1);
?>
<form action="?id=foo" method="post">
    <input type="submit" name="sub1" value="bar">
</form>

Upvotes: 0

Saeed
Saeed

Reputation: 118

Use $_REQUEST.
but it's not good recommendation.
read this: Among $_REQUEST, $_GET and $_POST which one is the fastest?

Upvotes: 1

steadweb
steadweb

Reputation: 16551

Use $_REQUEST.

An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.

http://php.net/manual/en/reserved.variables.request.php

Upvotes: 1

Related Questions