php upload mysql

Reply

Join Date: May 2009
Posts: 18
Reputation: DaveyMoyes is an unknown quantity at this point 
Solved Threads: 0
DaveyMoyes DaveyMoyes is offline Offline
Newbie Poster

php upload mysql

 
0
  #1
May 23rd, 2009
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
  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
  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
  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.
why did I ever start.....
If you have helped me in the past, or you help me in the future.
I say thanks to you all
it is appreciated
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: danishbacker is an unknown quantity at this point 
Solved Threads: 5
danishbacker's Avatar
danishbacker danishbacker is offline Offline
Junior Poster in Training

Re: php upload mysql

 
0
  #2
May 25th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 18
Reputation: DaveyMoyes is an unknown quantity at this point 
Solved Threads: 0
DaveyMoyes DaveyMoyes is offline Offline
Newbie Poster

Re: php upload mysql

 
0
  #3
May 25th, 2009
Originally Posted by danishbacker View Post
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....
why did I ever start.....
If you have helped me in the past, or you help me in the future.
I say thanks to you all
it is appreciated
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: danishbacker is an unknown quantity at this point 
Solved Threads: 5
danishbacker's Avatar
danishbacker danishbacker is offline Offline
Junior Poster in Training

Re: php upload mysql

 
0
  #4
May 25th, 2009
plz dont get me wrong, i think u already know this.
but what to do this is the answer.
  1. mysql_query("INSERT INTO table_name (member, img1, img2,img3) VALUES ($var1, $var2, $var3, $var4)");
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC