Jump to content

foreach($_POST as $k => $v)


digitalgod

Recommended Posts

I have a form that has text fields and file fields is there any way I can collect the info from both of them at the same time using this

[code]
$qtmp = array();
            foreach($_POST as $k => $v)
                switch($k) {
                    case 'club_name':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "club ='" . mysql_real_escape_string(trim(stripslashes($v))) . "'";
                    break;
                    case 'event_name':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "name ='" . $v . "'";
                    break;
                    case 'dj':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "dj ='" . mysql_real_escape_string(trim(stripslashes($v))) . "'";
                    break;
                    case 'performers':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "performers ='" . mysql_real_escape_string(trim(stripslashes($v))) . "'";
                    break;
                    case 'promoter':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "promoter ='" . mysql_real_escape_string(trim(stripslashes($v))) . "'";
                    break;
                    case 'dress':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "dress ='" . mysql_real_escape_string(trim(stripslashes($v))) . "'";
                    break;
                    case 'notes':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "notes ='" . mysql_real_escape_string(trim(stripslashes($v))) . "'";
                    break;
                    case 'buy':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "tickets ='" . mysql_real_escape_string(trim(stripslashes($v))) . "'";
                    break;
                    case 'guestlist':
                        if (trim(stripslashes($v)) != '')
                            $qtmp[] = "guestlist ='" . mysql_real_escape_string(trim(stripslashes($v))) . "'";
                    break;  
         }
         
           $query = "INSERT INTO ".$prefix."events set " . implode(', ',$qtmp);
           $result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
[/code]

reason I want that is because the part that controls the file uploading stores the names of the files in an array array_push($names,$file_name); so that I can sttore those names in the db.

got 4 file fields named file1 file2 file3 and file4 and the db row names are flyer1 flyer2 flyer3 and flyer4

any way I can make it work with the script I already have without having to add a 2nd query?
Link to comment
https://forums.phpfreaks.com/topic/10748-foreach_post-as-k-v/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.