How to grab all variables in a post (PHP)?
I don't want to deal with $_POST['var1']; $_POST['var2']; $_POST['var3']; ...
I want to echo all of them in one shot.
PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables. The example below shows a form with an input field and a submit button.
Solution. When you use the $_GET variable to collect data, the data is visible to everyone.
The PHP built-in variable $_POST is also an array and it holds the data that we provide along with the post method.
The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
If you really just want to print them, you could do something like:
print_r($_POST);
Alternatively, you could interact with them individually doing something like:
foreach ($_POST as $key => $value) {
//do something
echo $key . ' has the value of ' . $value;
}
but whatever you do.. please filter the input. SQL Injection gives everyone sleepless nights.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With