I'm interested to see the raw query we're submitting to the SQL server.

Do this for me... on that same script we edited earlier, circa line
36 (after a call to mysql_query(); ) ADD the following code:

$fp = fopen('c:/mytest.txt', 'wb');
fwrite($fp, $query);
fclose($fp);

Then, attach 'c:\mytest.txt' to your post.

    Can you paste the source of the code we've been editing? The function isn't doing it's job!

      Yes, of course. Here is the source. 🙂

      <?php

      include "C:\Program Files\Apache Group\Apache\conf\Connect.php";

      set_time_limit(1000);

      if($Name1==Null || $EmailAddress==Null || $Name2==Null || $City==Null)
      {
      header('Location: http://mydomain.com/KSBY/index.php?Error=Yes');
      }

      if($_FILES['File']['size']<1)
      {
      header('Location: http://mydomain.com/KSBY/index.php?Error=Yes');
      }

      else
      {

      $FileName=$_FILES['File']['name'];
      $TempName=$_FILES['File']['tmp_name'];
      $FileSize=$_FILES['File']['size'];
      $FileType=$_FILES['File']['type'];
      
      $ftp=fopen($TempName, 'r');
      $Content=fread($ftp, filesize($TempName));
      $Content=mysql_real_escape_string($Content);
      
      fclose($ftp);
      
      if(!get_magic_quotes_gpc())
      {
      	$FileName=addslashes($FileName);
      }
      
      
      mysql_select_db("ksbytv");
      $Query="INSERT INTO halloweenpictures (Number, Name1, EmailAddress, Name2, City, PronunciationGuide, Comments, FileName, Type, Size, Content, Status1, Status2, Option1, Option2, Option3, Option4, Option5) VALUES (NULL, '$Name1', '$EmailAddress', '$Name2', '$City', '$PronunciationGuide', '$Comments', '$FileName', '$FileType', '$FileSize', '$Content', 'New', 'New', NULL, NULL, NULL, NULL, NULL)";
      mysql_query($Query);
      
      $fp=fopen('c:/mytest.txt', 'wb'); 
      fwrite($fp, $Query); 
      fclose($fp);
      
      $Header="From: [email]halloweenpics@ksby.com[/email]\r\n";
      mail($EmailAddress, "Submission Confirmation", "$Name1,\nThank you for submitting your Halloween picture to KSBY, the Central Coast's local news leader.  Watch Action News, weekdays from 6-7 p.m. starting October 20th, for Halloween pictures from your community.\n\nTo purchase a VHS or DVD copy of your child's Halloween picture on-air, please call (805) 541-6666 extension 601.", $Header);
      
      move_uploaded_file ("$TempName", "C:\Program Files\Apache Group\Apache\htdocs\KSBY\Upload\$FileName");
      
      
      header("Location: [url]http://mydomain.com/KSBY/Confirmation.php?EmailAddress=[/url]$EmailAddress");

      }

      ?>

        Do you have magic_quotes_gpc enabled?

        If so, change:

        $Content=mysql_real_escape_string($Content); 

        to:

        $Content=stripslashes($Content); 
        $Content=mysql_real_escape_string($Content); 

          Yes, I have that on. I tried adding that one line of code. But it didn't quite do it. The record still doesn't show up in the database.

            You're turning out to be quite a hard case.

            Another thing that's got me curious: chunking.

            You said smaller files uploaded just fine?

            First, let's try this. Change this:

            	$ftp=fopen($TempName, 'r');

            to this:

            	$ftp=fopen($TempName, 'rb');

              Sorry. I wish it were an easy fix too. I added the "b" and the record still does not show up in the database.

                :glare: @ your SQL server.

                Alrighty then, let's try a different approach.

                Change:

                	$ftp=fopen($TempName, 'rb');
                	$Content=fread($ftp, filesize($TempName));
                	$Content=addslashes($Content);
                	fclose($ftp);

                to this:

                	$Content = addslashes(fread(fopen($TempName, "r"), filesize($TempName)));

                EDIT: After you make that change and test it, if it still fails, add the binary 'b' flag to the fopen() and test again.

                ALSO: After you make this change and if it still doesn't work, try uploading a smaller file (one that has worked before) and make sure it still works!

                  I tried it with the change.... and it didn't go into the database.
                  I tried it with the change and the b for binary, and it didn't go into the database. Both of the above were with the large 1,500 kb file.

                  I tried it with the <1000kb file, and it worked.

                    OK, so it's not 100% broken yet. That's good.

                    I'm going to try that other approach I didn't like previously:

                    Change:

                    	$Content = addslashes(fread(fopen($TempName, "r"), filesize($TempName)));

                    to this:

                    	$Content = base64_encode(fread(fopen($TempName, 'r'), $FileSize));

                    and give her a go.

                      I tried it... $Content = base64_encode(fread(fopen($TempName, 'r'), $FileSize));

                      However, the record does not appear in the database.

                      Here's the last couple lines of the MySQL error doc....

                      #define ER_TOO_MUCH_AUTO_TIMESTAMP_COLS 1293
                      "Incorrect table definition; There can only be one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause"
                      #define ER_INVALID_ON_UPDATE 1294
                      "Invalid ON UPDATE clause for '%-.64s' field",
                      #define ER_UNSUPPORTED_PS 1295
                      "This command is not supported in the prepared statement protocol yet",

                        Remember that code I had you add so that it print's $query to a file?

                        Can you re-add that code again now, using the new method, and give me a link to the file?

                          It's getting late here. I'm tired. You must be too. So I'm going to go to bed. Thanks for all your help again.

                            Yeah, I'm a bit tired. Should be doing my homework, teehee.

                            I'm gonna post another solution. Try it whenever you have time and get back to me on it.

                              sigh I know it said it would make it a bit larger when encoded.. but DANG.

                              Ok, so I've exhausted all possibilities.... except one. Chunking. Splitting up a file larger than 1000kb and sending it to MySQL in chunks of.. 500kb to be safe. Let's try that.

                              NOTE: Before making the following change, I ASSUMED that the "Number" field was type AUTO_INCREMENT. If this is INCORRECT, do NOT attempt the following change, and notify me.

                              Change:

                              $Content = base64_encode(fread(fopen($TempName, 'r'), $FileSize)); 

                              to:

                              $ftp=fopen($TempName, 'r');
                              $content = stripslashes(fread($ftp, 1024*500));
                              	$Query="INSERT INTO halloweenpictures (Number, Name1, EmailAddress, Name2, City, PronunciationGuide, Comments, FileName, Type, Size, Content, Status1, Status2, Option1, Option2, Option3, Option4, Option5) VALUES (NULL, '$Name1', '$EmailAddress', '$Name2', '$City', '$PronunciationGuide', '$Comments', '$FileName', '$FileType', '$FileSize', '" . mysql_real_escape_string($Content) . "', 'New', 'New', NULL, NULL, NULL, NULL, NULL)";
                              	mysql_query($Query);
                              
                              while(!feof($ftp)) {
                              $content = stripslashes(fread($ftp, 1024*500));
                                $query = "UPDATE halloweenpictures SET Content = CONCAT(Content, '" . mysql_real_escape_string($Content) . "') WHERE Number=last_insert_id() AND Name1='$Name1' AND EmailAddress='$EmailAddress' LIMIT 1";
                                mysql_query($Query);
                              }
                              fclose($ftp);

                              EDIT: Once again, if this does not work, try adding the binary 'b' flag.

                              EDIT2: Wewt! Post #200, right here baby 🆒

                                Well.... the new code made the file upload into different chunks as seperate database entries (rows). I'm a little confused about how I'm supposed to bring the information back together though. My pictures are all broken links now.

                                  yawn 'Morning!

                                  Can I view a dump of the structure of your table?