Submit all form fields?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Submit all form fields?

Post by Sindarin »

Is there something I can do instead of this:

Code: Select all

 
$row_dvd_player = strip_tags($_POST['row_dvd_player']);
$row_cd_player = strip_tags($_POST['row_cd_player']);
$row_mp3_player = strip_tags($_POST['row_mp3_player']);
 
There are like 200 fields in that form that also need to be inserted into a database! 8O

This did not work as expected:

Code: Select all

$x=0;
foreach($_POST as $key => $data) {
 
       $fields[$x]= $data;
       $x=x+1;
        echo $data.'<br/>'.$x;
  
}
 
echo 'VALUE: '.$fields[0].'<br/>';
Mind you, I have some file fields as well.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Submit all form fields?

Post by klevis miho »

Not sure for other types of input, but for checkboxes use the name="name[]" for example:

<input type="checkbox" name="test[]" value="value1" />
<input type="checkbox" name="test[]" value="value2" />

and then try a

print_r($_POST['test']);
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Submit all form fields?

Post by AbraCadaver »

Not sure what you are trying to eliminate, the strip_tags(), or the variable assignments? If I get it right, this is an example:

Code: Select all

$fields = "`".implode("`,`", array_keys($_POST))."`";
$values = "'".implode("','", array_map('stripslashes', $_POST))."'";
You could write your own function to use with arr_map() as well. Add a check for magic_quotes_gpc(), quote if not numeric, etc...
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply