tags:

views:

59

answers:

4

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?

+1  A: 

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.

dwich
Thats exactly what i need. But getting it out again is the problem.
Yustme
A: 

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?

Evernoob
im not sure if i said it correctly. I need to get some data out of POST. But i'm not getting all data. So im wondering how i can explicitly pass data to that POST thing.
Yustme
A: 

$_POST['value'] = "variable";

artuska
thats exactly what i did, but i cant get the value out again. i tried: $test = $_POST['value']; didn't work. So how would i get the value out again?
Yustme
A: 

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
frozen
$_POST, $_GET and others are superglobal variables, they don't need to be "globalized".
dwich
@dwich Actually, I do not suggest using global on superglobals. What gave you that idea???What I am saying is that Yustme might be using $_POST in a way that although it works, was never supposed to be used that way, so I suggested a way to do it *without* using any special variables.
frozen
If I understand the question correctly, it's about not having all info in $_POST array, possibly caused by incorrectly written HTML form. It's not about how or when to use global or variable scope.
dwich
So you think it might be as simple as adding square brackets after the name of an multiple option field?
frozen