Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to grab all variables in a post (PHP)

Tags:

post

forms

php

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.

like image 865
ilhan Avatar asked Jun 17 '10 01:06

ilhan


People also ask

What is $_ POST [] in PHP?

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.

When you use $_ POST variable to collect data the data is visible to?

Solution. When you use the $_GET variable to collect data, the data is visible to everyone.

Is $_ POST an array?

The PHP built-in variable $_POST is also an array and it holds the data that we provide along with the post method.

What does ?: Mean in PHP?

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.


1 Answers

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.

like image 193
CaseySoftware Avatar answered Sep 29 '22 07:09

CaseySoftware