php upload mysql
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>
<form action='upload.php' method='post' enctype='multipart/form-data'>
<input type='file' name='myfile'>
<input type='file' name='myfile1'>
<input type='file' name='myfile2'>
<input type='file' name='myfile2'><p>
<input type='file' name='myfile4'>
<input type='submit' value='upload'>
</form>
</html>
*******
I'v got one file uploading to a "uploaded" folder
***see below
<?php
// properties of uploaded file
$name = ($_FILES["myfile"]["name"]);
//$name = $_FILES["myfile"]["name"];
//$name = $_FILES["myfile2"]["name"];
//$name = $_FILES["myfile3"]["name"];
//$name = $_FILES["myfile4"]["name"];
$type = $_FILES["myfile"] ["type"];
$size = $_FILES["myfile"] ["size"];
$tempd = $_FILES["myfile"] ["tmp_name"];
$error = $_FILES["myfile"] ["error"];
if ($error > 0)
die ("Error uploading file code $error.");
else
{
if ($type == "image/png" || $size > 500000) //file conditions
{
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");
}
else
move_uploaded_file($tempd,"uploaded/".$name);
echo "Upload Completed";
{
} // end if, after else
} //end if b4 else
?>
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
echo "$foundnum results found<p>";
while ($runrows = mysql_fetch_assoc($run))
{
//get data
$category = $runrows['catname'];
//$subcategory = $runrows['subcategory'];
$subcats = $runrows['subcats'];
$catdes = $runrows['catdes'];
$keywords = $runrows['keywords'];
$imagelocation = $runrows['imagelocation'];
$img2 = $runrows['img2'];
//$img2 src='image/".$row['imagelocation']."' width='50' height='50'>
//show data as search results
echo "
$category<p>
$subcats
$catdes<p>
$keywords<p>
$imagelocation //enctype='multipart/form-data'
$img2 <img2 src='image/".$row['imagelocation']."' width='50' height='50'>
<img src='store/".$row['imagelocation']."' width='100' height='100' enctype='multipart/form-data'>
$img2<p>
";
many many thanks in advance if anyone can help me...
DaveyMoyes
Junior Poster in Training
70 posts since May 2009
Reputation Points: 10
Solved Threads: 0
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.
danishbacker
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 10
Solved Threads: 7
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....
DaveyMoyes
Junior Poster in Training
70 posts since May 2009
Reputation Points: 10
Solved Threads: 0
plz dont get me wrong, i think u already know this.
but what to do this is the answer.
mysql_query("INSERT INTO table_name (member, img1, img2,img3) VALUES ($var1, $var2, $var3, $var4)");
danishbacker
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 10
Solved Threads: 7