Unable To Post Full List To mySql Database

Last post 02-10-2012, 8:05 AM by IRHM73. 2 replies.
Sort Posts: Previous Next
  •  02-09-2012, 10:47 AM 72969

    Unable To Post Full List To mySql Database

    I wonder whether someone may be able to help me please.
     
    I thought I'd got this problem solved but unfortunately I still have some errors:
     
    I'm using the code below to upload and save image files to a mySql database.
     

    <?php require_once "phpuploader/include_phpuploader.php" ?>
    <?php session_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     <title>
      Form - Keeping state after submitting
     </title>
     <link href="demo.css" rel="stylesheet" type="text/css" />
      <script type="text/javascript">
     function doStart()
     {
      var uploadobj = document.getElementById('myuploader');
      if (uploadobj.getqueuecount() > 0)
      {
       uploadobj.startupload();
      }
      else
      {
       alert("Please browse files for upload");
      }
     }
     </script>
    </head>
    <body>
     <div class="demo">
       
         <h2>Simple Upload with Progress (Custom Validation) </h2>
     <ul>
         <li>Maximum file size: 1MB</li>
         <li>Allowed file types: <span style="color:red">bmp, jpg, jpeg, gif or png </span></li>
     </ul>
     <p>Click the following button to add the image file or files you wish to add for this find. Then click 'Start Uploading Files' to save these to your finds record.</p>

       <form id="form1" action="keepingstatetest2.php" method="POST">
        <?php

        $uploader=new PhpUploader();
        $uploader->MaxSizeKB=1024;
        $uploader->MultipleFilesUpload=true;
        $uploader->ManualStartUpload=true;
        $uploader->Name="myuploader";
        $uploader->InsertText="Select the file or files (Max 1MB)";
        $uploader->AllowedFileExtensions="*.bmp,*.gif,*.jpg,*.jpeg,*.png"; 
        $uploader->Render();

        ?>
        
        <br /><br /><br />
        <button id="submitbutton" onclick="doStart();return false;">Start Uploading Files</button>

        
    <?php

    $files=array();

    $processedlist=@$_POST["processedlist"];
    if($processedlist)
    {
     $guidlist=explode("/",$processedlist);
     foreach($guidlist as $fileguid)
     {
      $mvcfile=$uploader->GetUploadedFile($fileguid);
      if($mvcfile)
      {
       array_push($files,$mvcfile);
      }
     }
    }
    $fileguidlist=@$_POST["myuploader"];
    if($fileguidlist)
    {
     $guidlist=explode("/",$fileguidlist);
     foreach($guidlist as $fileguid)
     {
      $mvcfile=$uploader->GetUploadedFile($fileguid);
      if($mvcfile)
      {
      
       
       if($processedlist)
        $processedlist= $processedlist . "/" . $fileguid;
       else
        $processedlist= $fileguid;
      
       array_push($files,$mvcfile);
      }
     }
    }

    if(count($files)>0)
    {
     echo("<table style='border-collapse: collapse' class='Grid' border='0' cellspacing='0' cellpadding='2'>");
     foreach($files as $mvcfile)
     {
      echo("<tr>");
      echo("<td>");echo("<img src='phpuploader/resources/circle.png' border='0' />");echo("</td>");
      echo("<td>");echo($mvcfile->FileName);echo("</td>");
      echo("<td>");echo($mvcfile->FileSize);echo("</td>");
      echo("</tr>");
      
      //Moves the uploaded file to a new location.
      //$mvcfile->MoveTo("/uploads");
      //Copys the uploaded file to a new location.
      //$mvcfile->CopyTo("/uploads");
      //Deletes this instance.
      //$mvcfile->Delete();
     }
     echo("</table>");
    }

    ?>
    <?php

    mysql_connect("hostname", "username", "password")or
     die(mysql_error());
    mysql_select_db("database");

    if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
      if (isset($_POST["submitform"]))
      {
      $result = mysql_query("INSERT into testimages (imagename)values('$mvcfile->FileName')");
    }
    }
     ?>
        <input type='hidden' name='processedlist' value='<?php echo($processedlist) ?>' />
        <input type='submit' name="submitform" value="Submit Form" /> 
       </form>
       
        
     </div>
    </body>
    </html>
     
    I can select and delete the files from the pre-upload list, I can also select to upload the desired files populating the 'processed list'. However the problem I have is that when I click 'Submit Form' to save the filename to my database only the first file is saved.
     
    I've tried all sorts of permuatations for the code but I just can't find the answer.
     
    I just wondered whether someone could perhaps take a look at this and let me know where I'm going wrong.
     
    Many thanks and kind regards
     
    Chris
    Filed under:
  •  02-10-2012, 7:29 AM 72978 in reply to 72969

    Re: Unable To Post Full List To mySql Database

    Hi Chris,
     
    This is the coding problem, you should save the file info in method below not out of it.
     
    foreach($files as $mvcfile)
     {

    }  
     
    Regards,
     
    Ken 
  •  02-10-2012, 8:05 AM 72979 in reply to 72978

    Re: Unable To Post Full List To mySql Database

    Hi Ken, many thanks for getting back to me so quickly.
     
    I had worked it out, eventually, and I edited my orignal post to reflect this, so I'm not sure whether it's been procesed yet.
     
    Kind regards
     
    Chris
View as RSS news feed in XML