Jump to content


Photo

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


  • Please log in to reply
1 reply to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 30 May 2006 - 02:37 AM

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

$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());

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?

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 30 May 2006 - 05:35 PM

why not just add another loop for $_FILES before $query?
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users