Hi,
How can I pass a value/variable to $_POST? Im not getting all data to my php function. So i just figured out to pass them explicitly.
Can anyone tell me how this is done?
Hi,
How can I pass a value/variable to $_POST? Im not getting all data to my php function. So i just figured out to pass them explicitly.
Can anyone tell me how this is done?
Check what's in $_POST
and then check your HTML form if it's correct.
print '<pre>';
print_r($_POST);
print '</pre>';
Or you can directly assign value to $_POST
as it's (almost) a normal array:
$_POST['test'] = 'hi';
But I suppose that's not what you're looking for.
the $_POST array is used to retrieve the data that has been sent to your PHP page/script with an HTTP POST request.
Are you asking how to explicitly assign values to $_POST without it being automatically assigned in the request? If so, why would you want to do this?
If I am reading your question right, you want to pass a value from outside the scope of the function, to inside it's scope, right? This usually is unnecessary when using proper code paradigms in PHP, but you can access a global variable from inside a function using the global keyword.
The global keyword in use:
$test = 1;
function funca() {
global $test,$foo;
$test = 2;
$foo = 8;
}
function funcb() {
global $test,$foo;
@echo $test."\n";
@echo $foo."\n";
}
funcb(); // prints 1 and gives error
funca();
funcb(); // prints 2 and 8