Need help with image upload into database

Hello everyone …
my head got stuck already…because my code not working for the upload image into database…
it just save the data only not the image the filed for the image still remain empty…huh…hope someone
expert in this forum can point me to the rite path…
just curious can I dynamically create folder for each individual to stored the image…?is it possbile?
if not ignore it…
hope someone can help me out…here’s the code…


<? if($_POST['Submit']){
            
            $date=$_POST['date'];
	    $p=$_POST['p'];
	    $premiseadd1=$_POST['premiseadd1'];
	    $premiseadd2=$_POST['premiseadd2'];
	    $pzip=$_POST['pzip'];
	    $ptown=$_POST['ptown'];
	    $pstate=$_POST['pstate'];
	    $amount=$_POST['amount'];
	    $pdesc=$_POST['pdesc'];

////////////this portion for upload my image and it's not working at all/////
	
	$path_to_file = 'himage/';
	$files = $HTTP_POST_FILES['imej'];
	
	$errmsg = 'The following error occur during uploading file(s):
';
	
	if($files['tmp_name'])
	{
		$img = getimagesize($files['tmp_name']);
		$maxSize = 2000000; //2M size is the limit
					
		if ($files['size'] > $maxSize)
		{
			$errmsg .= '- file '.$files['name'].' exceeding limit size of '.$maxSize.'M
';
			$startErrorMsg = 1;
			//continue;
		
		}else if($img[2]==0){ //check weather image type is valid
			$errmsg .= '- file '.$files['name'].' has an invalid image type
';
			$startErrorMsg = 1;
			//echo $errmsg2;
		}else{
			
			 // clean up file name
			 $name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($name))));
			 $location = $path_to_file."/".$name;

			 if (!file_exists($location))	
			 { //$location .= ".copy"; 
				 @copy($files['tmp_name'],$location);
				 $size = @getimagesize($files['tmp_name']);
				 $resolution = $size[0]. ' x ' . $size[1];
			 
				 @unlink($files['tmp_name']);			 
				 $db->db_insert("INSERT INTO advertisement SET filename='".$name."', size='".$files['size']."', type='".$files['type']."', resolution='".$resolution."'");
			 }		 
		}
	}

//////////////////done for the iamge upload part///////////////////////

	$link = mysql_connect ("localhost","","") or die('Could not connect: ' . mysql_error());
	mysql_select_db("4u2rent");
	$query = "INSERT INTO advertisement SET 
					date='$date',
					   p='$p',
			 premiseadd1='$premiseadd1',
			 premiseadd2='$premiseadd2',
					pzip='$pzip',
				   ptown='$ptown',
				   pstate='$pstate',
				   amount='$amount',
					pdesc='$pdesc'
					";
	
	

	$loginstuff = mysql_query($query) or die(mysql_error());

	mysql_close($link);

}//end submit
?>