title: multiple image upload using php mysql javascript
body: <p>hi i want to upload multiple images and insert into mysql db  using a single form with php, mysql and javascript. i'm applying coding. php upload will works fine. but javascript code for multiple select not working. i'm setting + and _ symbol for add or delete multiple select boxes  for selection and upload in a single submit. the upload and insert db  works fine.but the incement(+) symbol not working. i'm able to upload only one image at a time. i'm displayed the code below. please help me.</p>
  
  <p>index.php:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Multiple Upload&lt;/title&gt;
  &lt;/head&gt;
  &lt;script language="javascript"&gt;
      function fncCreateElement(){
  
         var mySpan = document.getElementById('mySpan');
  
         var myLine = document.getElementById('hdnLine');
         myLine.value++;
  
         // Create input text
         var myElement1 = document.createElement('input');
         myElement1.setAttribute('type',"text");
         myElement1.setAttribute('name',"txtGalleryName"+myLine.value);
         myElement1.setAttribute('id',"txt"+myLine.value);
         mySpan.appendChild(myElement1);  
  
         // Create input file
         var myElement2 = document.createElement('input');
         myElement2.setAttribute('type',"file");
         myElement2.setAttribute('name',"fileUpload"+myLine.value);
         myElement2.setAttribute('id',"fil"+myLine.value);
         mySpan.appendChild(myElement2);  
  
         // Create &lt;br&gt;
         var myElement3 = document.createElement('&lt;br&gt;');
         myElement3.setAttribute('id',"br"+myLine.value);
         mySpan.appendChild(myElement3);
      }
  
      function fncDeleteElement(){
  
          var mySpan = document.getElementById('mySpan');
  
          var myLine = document.getElementById('hdnLine');
  
          if(myLine.value &gt; 1 )
          {
  
              // Remove input text
              var deleteFile = document.getElementById("txt"+myLine.value);
              mySpan.removeChild(deleteFile);
  
              // Remove input file
              var deleteFile = document.getElementById("fil"+myLine.value);
              mySpan.removeChild(deleteFile);
  
              // Remove &lt;br&gt;
              var deleteBr = document.getElementById("br"+myLine.value);
              mySpan.removeChild(deleteBr);
  
              myLine.value--;
          }
      }
  &lt;/script&gt;
  &lt;body&gt;
      &lt;form action="upload.php" method="post" name="form1" enctype="multipart/form-data"&gt;
          &lt;input type="text" name="txtGalleryName1"&gt;&lt;input type="file" name="fileUpload1"&gt;
          &lt;input name="btnCreate" type="button" value="+" onClick="JavaScript:fncCreateElement();"&gt;
          &lt;input name="btnDelete" type="button" value="-" onClick="JavaScript:fncDeleteElement();"&gt;&lt;br&gt;   
          &lt;span id="mySpan"&gt;&lt;/span&gt;
          &lt;input name="hdnLine" type="hidden" value="1"&gt;
          &lt;input name="btnSubmit" type="submit" value="Submit"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  upload.php:
  
  &lt;?php
  include("config.php");
          for($i=1;$i&lt;=(int)($_POST["hdnLine"]);$i++)
          {
              if($_FILES["fileUpload".$i]["name"] != "")
              {
                  if(copy($_FILES["fileUpload".$i]["tmp_name"],"shotdev/".$_FILES["fileUpload".$i]["name"]))
                  {
                      $strSQL = "INSERT INTO gallery ";
                      $strSQL .="(GalleryName,Picture) VALUES ('".$_POST["txtGalleryName".$i]."','".$_FILES["fileUpload".$i]["name"]."')";
                      mysql_query($strSQL);
                      echo "Copy/Upload ".$_FILES["fileUpload".$i]["name"]." completed.&lt;br&gt;";
                  }
              }
          }
  
          echo "&lt;br&gt;&lt;a href='view.php'&gt;View file&lt;/a&gt;";
  
          mysql_close();
      ?&gt;
  </code></pre>