943,575 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 617
  • PHP RSS
May 23rd, 2009
0

php upload mysql

Expand Post »
Hi this is my first post on DaniWeb.... the information has helped me in the past but im seriously stuck.... Help would be very much appreciated..

Im trying to create a form where the user can upload 5 pictures to a mysql database (members) field names are img1, img2, img3, img4, img5.. i have read to design the img fields as varchar100 ??? and for my form to insert the location of the files?? into the database.
********upload form
html Syntax (Toggle Plain Text)
  1. <html>
  2.  
  3. <form action='upload.php' method='post' enctype='multipart/form-data'>
  4. <input type='file' name='myfile'>
  5. <input type='file' name='myfile1'><br>
  6. <input type='file' name='myfile2'>
  7. <input type='file' name='myfile2'><p>
  8. <input type='file' name='myfile4'>
  9. <input type='submit' value='upload'>
  10.  
  11. </form>
  12. </html>
*******

I'v got one file uploading to a "uploaded" folder
***see below
php Syntax (Toggle Plain Text)
  1. <?php
  2. // properties of uploaded file
  3. $name = ($_FILES["myfile"]["name"]);
  4. //$name = $_FILES["myfile"]["name"];
  5. //$name = $_FILES["myfile2"]["name"];
  6. //$name = $_FILES["myfile3"]["name"];
  7. //$name = $_FILES["myfile4"]["name"];
  8. $type = $_FILES["myfile"] ["type"];
  9. $size = $_FILES["myfile"] ["size"];
  10. $tempd = $_FILES["myfile"] ["tmp_name"];
  11. $error = $_FILES["myfile"] ["error"];
  12.  
  13. if ($error > 0)
  14. die ("Error uploading file code $error.");
  15.  
  16. else
  17. {
  18. if ($type == "image/png" || $size > 500000) //file conditions
  19. {
  20. die ("File exceeds maximum file size limit of 0.5mb, saving the file as a JPG or GIF will reduce the overall size of the file");
  21. }
  22. else
  23. move_uploaded_file($tempd,"uploaded/".$name);
  24. echo "Upload Completed";
  25. {
  26.  
  27. } // end if, after else
  28.  
  29. } //end if b4 else
  30.  
  31. ?>

but what i dont understand is how i tell the database where the file is ?? and how do i show the file in a mysql query... I have my search working fine as the results are what im expecting them to be...
but these F'n images just will not show >> please please help

***my search
php Syntax (Toggle Plain Text)
  1. echo "$foundnum results found<br><p>";
  2.  
  3. while ($runrows = mysql_fetch_assoc($run))
  4. {
  5. //get data
  6. $category = $runrows['catname'];
  7. //$subcategory = $runrows['subcategory'];
  8. $subcats = $runrows['subcats'];
  9. $catdes = $runrows['catdes'];
  10. $keywords = $runrows['keywords'];
  11. $imagelocation = $runrows['imagelocation'];
  12. $img2 = $runrows['img2'];
  13. //$img2 src='image/".$row['imagelocation']."' width='50' height='50'>
  14. //show data as search results
  15. echo "
  16. $category<p><br>
  17. $subcats<br>
  18. $catdes<br><p>
  19. $keywords<p>
  20. $imagelocation //enctype='multipart/form-data'
  21. $img2 <img2 src='image/".$row['imagelocation']."' width='50' height='50'>
  22. <img src='store/".$row['imagelocation']."' width='100' height='100' enctype='multipart/form-data'>
  23. $img2<p>
  24.  
  25. ";

many many thanks in advance if anyone can help me...
Last edited by peter_budo; May 24th, 2009 at 3:19 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
DaveyMoyes is offline Offline
38 posts
since May 2009
May 25th, 2009
0

Re: php upload mysql

Mr. DaveyMoyes
you havent inserted the filename/path in to database while uploading. I this is why the file name is not showing.
Try inserting those img names to corresponding columns.
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
danishbacker is offline Offline
97 posts
since Apr 2008
May 25th, 2009
0

Re: php upload mysql

Mr. DaveyMoyes
you havent inserted the filename/path in to database while uploading. I this is why the file name is not showing.
Try inserting those img names to corresponding columns.
**** hi many thanks.... How can i do this.... im really new to php and this is causing me sooo many sleepless nights....

Can you help me on this please....
Reputation Points: 10
Solved Threads: 0
Light Poster
DaveyMoyes is offline Offline
38 posts
since May 2009
May 25th, 2009
0

Re: php upload mysql

plz dont get me wrong, i think u already know this.
but what to do this is the answer.
PHP Syntax (Toggle Plain Text)
  1. mysql_query("INSERT INTO table_name (member, img1, img2,img3) VALUES ($var1, $var2, $var3, $var4)");
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
danishbacker is offline Offline
97 posts
since Apr 2008
Nov 23rd, 2010
0
Re: php upload mysql
hi, it might be late, but i already manage to store 5 image at one time in blob. Can refer to below code..Can refer to attachment for full code.hopefully might help you.

PHP Syntax (Toggle Plain Text)
  1. if ($submit == "Simpan Aktiviti")
  2. {
  3. //insert into event table
  4. $sqlm = "INSERT INTO event (bilangan_e,tarikh,keterangan_e,turutan) VALUES ('$bilangan_e','$tarikh','$keterangan_e','$bilangan_e')";
  5. $result = mysql_query($sqlm);
  6.  
  7.  
  8. //insert into event_details
  9.  
  10. if(isset($Ya)== "checked")
  11. {
  12. for($i = 1;$i<6 ;$i++)
  13. {
  14.  
  15. $kom = $_POST['komen_gambar'.$i];
  16.  
  17. global $strDesc;
  18. $max_size = 1000000000;
  19. $fileUpload = $HTTP_POST_FILES['fileUpload'.$i]['tmp_name'] ;
  20. if($fileUpload != NULL)
  21. {
  22. $fileUpload_name=$HTTP_POST_FILES['fileUpload'.$i]['name'];
  23. $fileUpload_size=$HTTP_POST_FILES['fileUpload'.$i]['size'];
  24. $fileUpload_type=$HTTP_POST_FILES['fileUpload'.$i]['type'];
  25.  
  26. $fileHandle=fopen($fileUpload, "rb");
  27. $fileContent=fread($fileHandle,filesize($fileUpload));
  28. $fileContent=addslashes($fileContent);
  29. fclose($fileHandle);
  30.  
  31. //checking pic - only can add 5 image
  32. $sqlcheck = "SELECT * from event_detail WHERE bilangan_e = '$bilangan_e'" ;
  33. $result = mysql_query($sqlcheck);
  34. $myrow1 = mysql_fetch_array($result);
  35. $kira = mysql_num_rows($result);
  36. if ($kira < 6)
  37. {
  38. $kira = $kira + 1;
  39. $sqls = "INSERT INTO event_detail (bilangan_e,tarikh,bilangan_ed,gambar,keterangan,jenis_gambar,tarikh_kemaskini) VALUES
  40. ('$bilangan_e','$tarikh',$kira,'$fileContent','$kom','$fileUpload_type',NOW())";
  41. $result = mysql_query($sqls);
  42.  
  43. $message= '<span style="width: 600; height: 30; font-size: 20px; font-family: verdana; color: #FF0000; ">Maklumat event baru dan upload gambar telah berjaya dimasukkan.</span><br>';
  44. }
  45. else
  46. {
  47. $message= '<span style="width: 600; height: 30; font-size: 20px; font-family: verdana; color: #FF0000;">Maaf.Anda telah melebihi had upload gambar sebanyak lima (5).</span><br>';
  48.  
  49.  
  50. }
  51.  
  52.  
  53. }//if fileupload null
  54. }//for
  55. }
  56. else
  57. {
  58. $message= '<span style="width: 600; height: 30; font-size: 20px; font-family: verdana; color: #FF0000; ">Maklumat event baru dan upload gambar telah berjaya dimasukkan.</span><br>';
  59. }
  60.  
  61.  
  62. $flag = true;
  63. }
  64. else
  65. {
  66. $message ="";
  67. $flag = false;
  68. }
Attached Files
File Type: php new_foto.php (11.4 KB, 15 views)
Reputation Points: 10
Solved Threads: 0
Light Poster
red_ruewei is offline Offline
37 posts
since Jun 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: .how do i start developing an online examintation? HELP!
Next Thread in PHP Forum Timeline: parse error, expecting `T_FUNCTION'





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC