Reputation: 25
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
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
Reputation: 118
Use $_REQUEST
.
but it's not good recommendation.
read this: Among $_REQUEST, $_GET and $_POST which one is the fastest?
Upvotes: 1
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