Click here to Skip to main content
15,913,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use a variable to pickup posts with filter_input()
The code is as follows:
PHP
for ($i='1'; $i<='10'; $i++)
{
      $childname = "ChildsName".$i;
      print "childname = $childname<br />";
      $ChildsName = filter_input(INPUT_POST,'$childname');
      print "$i. $ChildsName<br />\n";

}
I am positive that the post ChildsName1 is coming through as Eliza but it does not show in the above print statements. It comes back null.
The first print shows $childname to be ChildsName1 as it should be.

I don't want to have to repeat the code 10 times....

Thanks, your help is appreciated.
Hal
Posted

Looks to me like too many quotes!

In
$ChildsName = filter_input(INPUT_POST,'$childname');
you are searching for a variable literally named $childname but
$ChildsName = filter_input(INPUT_POST, $childname);
should do what you want.

(Advanced section) You might want to read up on filter_input_array(). It could save you looping at all. There are also filter_var() and filter_var_array() which might be worth a look. Out of this lot, you should find something that fits.

Cheers,
Peter

If you like it, vote and accept
 
Share this answer
 
Comments
Sandeep Mewara 2-Feb-11 23:54pm    
Voted! :)
Thanks - removing the quotes fixed the problem. I will also look into the filter_input_array and filter_var() statements when I get a chance.
Thanks again for your help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900