Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.