Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4032782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:45:52+00:00 2026-05-20T11:45:52+00:00

I have a form with various fields the user need to feel out with

  • 0

I have a form with various fields the user need to feel out with the option of attaching number of images:

 <?php
    $num = 0;
    while($num < $num_uploads)
    {
        echo '<div><input name="userfile[]" type="file" /></div>';
        $num++;
    }
 ?>

After submission it creates a table in the database, called “album” which looks something like this:

function create_album($params)
{
   db_connect();

     $query = sprintf("INSERT INTO albums set
                                     albums.title = '%s',
                                                                 albums.email = '%s',
                                                                 albums.discuss_url = '%s',
                                                                 albums.theme_id = '%s',
                                                                 albums.fullname = '%s',
                                                                 albums.description = '%s',
                                                                 created_at = NOW()",
                                                                 mysql_real_escape_string($params['title']),
                                                                 mysql_real_escape_string($params['email']),
                                                                 mysql_real_escape_string($params['discuss_url']),
                                                                 mysql_real_escape_string($params['theme_id']),
                                                                 mysql_real_escape_string($params['fullname']),
                                                                 mysql_real_escape_string($params['description'])
                                                                 );

     $result = mysql_query($query);
     if(!$result)
     {
          return false;
     }

     $album_id = mysql_insert_id();

     return $album_id;
}   

I want the files, however to go to “images” table and link to the correct album.

$create_album = create_album($_POST['album']);

                   mysql_query( "INSERT INTO images(`name`,`album_id`) VALUES('$newName', '$create_album')" );

I am having the problem is attaching those multiple images(the user can choose to submit one or 2, or 3 files) with one form submission to one album. Right now, if the user submit 3 files it creates 3 albums with every form submission.

Finally, this is my database structure:

CREATE TABLE `albums` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(50) NOT NULL,
  `fullname` varchar(40) NOT NULL,
  `discuss_url` varchar(150) NOT NULL,
  `email` varchar(100) NOT NULL,
  `created_at` datetime NOT NULL,
  `theme_id` int(11) NOT NULL,
  `description` int(11) NOT NULL,
  `vote_cache` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;



CREATE TABLE `images` (
  `id` int(11) NOT NULL auto_increment,
  `album_id` int(11) NOT NULL,
  `name` varchar(30) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:45:53+00:00Added an answer on May 20, 2026 at 11:45 am

    I just wanted to run quick update on this issue. Perhaps I didn’t give enough info which was important to see the problem. This article explains it very well. Basically the album was created each time the file was submitted, but not the form.

    So here is my form(working):

    <?php if (!isset($_POST['btnSubmit'])) { ?>
    <form action="index.php?view=create" method="post" enctype="multipart/form-data">
        <fieldset>
         <div>
                 <label><b>Title:</b></label>
    
                 <input name="album[title]" size="40" type="text" value="" class="textfield" />
                 </div>
    
                <div>
               <label><b>Fullname</b></label>
               <input name="album[fullname]" size="40" type="text" value="" class="textfield" />
                </div>
    
                <div>
    
               <label><b>Attach Photo</b> </label>
                    <input type="hidden" name="" value="" />
     <?php
        $num = 0;
        while($num < $num_uploads)
        {
            echo '<div><input name="userfile[]" type="file" /></div>';
            $num++;
        }
     ?>
    

    Here is php (I cut out some of it so it is easier):

        //If form was submitted
        if (isset($_POST['btnSubmit'])) {
    
        create_album($_POST['album']);
        $find_album_id = mysql_insert_id();
    
            /*** check if a file has been submitted ***/
            if(isset($_FILES['userfile']['tmp_name']))
            {
                /** loop through the array of files ***/
                for($i=0; $i < count($_FILES['userfile']['tmp_name']);$i++)
                {
    
                  $ext = strrchr($imgName, ".");
    
                   // then create a new random name
                  $newName = md5(rand() * time()) . $ext;
    
                          if (is_image_types($_FILES['userfile']['type'][$i]) 
                          and is_valid_file_size($_FILES['userfile']['size'][$i])
                          and is_uploaded_file($_FILES['userfile']['tmp_name'][$i])
                          and is_valid_width_height($_FILES['userfile']['tmp_name'][$i])
                       )
                      {    
    
                           mysql_query("INSERT INTO images(name, album_id) VALUES('$newName', '$find_album_id')") ; 
                           copy($_FILES['userfile']['tmp_name'][$i], './photos/'.$original_dir.'/' .$newName.'.jpg');
    
                }
    
                else
                {
             $warning = "Click back error uploading file. 
                                 Please make sure your file is a JPEG and less than 1MB";
                }
            }
        }
    
        }   
    
        break;
    }
    

    I hope it helps anyone who is looking…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form, in which I can set various client fields like client
I have a form which has a lot of SELECTs. For various reasons, I'd
I have a form with many input fields. When I catch the submit form
I need to create an input form that will allow a user to enter
I have a form with various inputs. I have a bunch of optional parameters
I have a contact form in my flash file with name/email/message fields which a
I have form area in my view. If I click button A , I
I have form that displays several keywords (standard set of choice lists that changes
I have a form in C# that has a button that, when clicked, I
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.