Is it possible to access each post variable where variable name should be accessible as
$_POST['field1'];
$_POST['field1'];
$_POST['field1'];
............so on
Edit: I am trying to pass $_post as an argument to a function and then inside the function I want to have each post variable accessible as a name on which i could then run operations.
It seems like you need just a simple example of a form and a php file that uses the information from the form after it's been submitted.
HTML
<form method="post" action="doStuff.php">
First Name:<input type="text" name="fname" />
Last Name:<input type="text" name="lname" />
<input type="submit" name="submit" value="submit" />
</form>
doStuff.php
if( isset($_POST["submit"}) ) {
$fname = $_POST["fname"];
$lname = $_POST["lname"];
processPOST($fname, $lname);
}
function processPOST($fname, $lname){
// Do whatever you need
}
or simply, doStuff.php The Second
if( isset($_POST["submit"}) ) {
$fname = $_POST["fname"];
$lname = $_POST["lname"];
// Do whatever you need
}
Take a look at extract
function PHP documentation here
Yes, you can easily pass $_POST
as an argument to a function.
function withPosts($_POST['field_name'], $field_name2){
//Some code here
}
But inside the function you have to refer them by variables as per function declaration.
function withPosts($field1, $field2){
echo $field1; // Correct
echo $_POST['field_name']; // Incorrect
}