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'><br>
    <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<br><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><br>
		$subcats<br>
		$catdes<br><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...

Recommended Answers

All 4 Replies

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.

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....

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)");

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.

if ($submit == "Simpan Aktiviti") 
{
	//insert into event table
	$sqlm = "INSERT INTO event (bilangan_e,tarikh,keterangan_e,turutan) VALUES ('$bilangan_e','$tarikh','$keterangan_e','$bilangan_e')";    
    $result = mysql_query($sqlm);
	
	
	//insert into event_details
	
	if(isset($Ya)== "checked")
	{
	  for($i = 1;$i<6 ;$i++)
	  {	
	  	
	  		$kom =  $_POST['komen_gambar'.$i];
			
			global $strDesc;
			$max_size = 1000000000;
			$fileUpload = $HTTP_POST_FILES['fileUpload'.$i]['tmp_name'] ;
			if($fileUpload != NULL)
			{
				  $fileUpload_name=$HTTP_POST_FILES['fileUpload'.$i]['name'];
				  $fileUpload_size=$HTTP_POST_FILES['fileUpload'.$i]['size'];
				  $fileUpload_type=$HTTP_POST_FILES['fileUpload'.$i]['type'];
				
				  $fileHandle=fopen($fileUpload, "rb");
				  $fileContent=fread($fileHandle,filesize($fileUpload));
				  $fileContent=addslashes($fileContent);
				  fclose($fileHandle);
				
				//checking pic - only can add 5 image
				$sqlcheck = "SELECT * from event_detail WHERE bilangan_e = '$bilangan_e'"  ;
				$result = mysql_query($sqlcheck);
   				$myrow1 = mysql_fetch_array($result);
				$kira = mysql_num_rows($result);
				if ($kira < 6)
				{
			      $kira = $kira + 1;
				  $sqls = "INSERT INTO event_detail (bilangan_e,tarikh,bilangan_ed,gambar,keterangan,jenis_gambar,tarikh_kemaskini) VALUES 
                  ('$bilangan_e','$tarikh',$kira,'$fileContent','$kom','$fileUpload_type',NOW())";    
      				$result = mysql_query($sqls);
					
					$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>';
				}
				else
				{
					$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>';
					
					
				}
				
				  
			}//if fileupload null
	  }//for
	}
	else
	{
		$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>';
	}
	
	
	$flag = true;
}
else
{
	$message ="";
	$flag = false;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.