Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Why does this query blow up?

This works:

	public function attachment_upload() {

	global $mysqli;
	
	$novie_id=$_POST['id'];
	
	if(isset($_FILES['attachment_1'])&& !empty($_FILES['attachment_1']['name']))
		{
		$pathinfo = pathinfo($_FILES['attachment_1']['name']);
		$new_name = $pathinfo['filename'].'_'.$novie_id.'.'.$pathinfo['extension'];
		$base_directory= "../attachments/"; 
		$target = $base_directory.''.$new_name;
		$url = $new_name;
		$uploadOk=1; 
		$fileParts = pathinfo( $url );
		$extension = $fileParts['extension'];
			if($extension=="jpg" OR $extension=="jpeg" OR $extension=="JPG" OR $extension=="GIF" OR  $extension=="gif" OR $extension=="PNG" OR $extension=="png" OR $extension=="doc" or 
			$extension=="docx" or $extension=="pdf" OR $extension=="xls" OR $extension=="xlsx" OR $extension=="ppt" OR $extension=="pptx" OR $extension=="txt" OR $extension=="pub" OR $extension=="wps"
			or $extension=="bmp" OR $extension=="BMP")
			{
				$uploadOk = 1;
			} 
			else 
			{
				$uploadOk = 0;
				header("Location: ../project_badfile.php");
				exit();
			}
		
			
			if(!move_uploaded_file($_FILES['attachment_1']['tmp_name'], $target))  
			{
				header("Location: ../project_no_upload.php");
				exit();
			}
			else 
			{
			  
			$sql_10 = "insert into attachments (project_id, url) values ('$novie_id', '$url')";
				if(!$query_10=$mysqli->query($sql_10))
				{
					$err_10='your attachments info didn\'t get uploaded becasue:'
					. 'ERRNO: '
					.$mysqli->errno
					. 'ERROR: '
					.$mysqli->error
					. 'and the query itself looks like this: '
					.$sql_10
					.PHP_EOL;
					trigger_error($err_2, E_USER_NOTICE);
				}
			}
		}
	}

Open in new window


This, however does not:

	public function attachment_upload() {

	global $mysqli;
	
	$novie_id=$_POST['id'];
	
	if(isset($_FILES['attachment_1'])&& !empty($_FILES['attachment_1']['name']))
		{
		$pathinfo = pathinfo($_FILES['attachment_1']['name']);
		$new_name = $pathinfo['filename'].'_'.$novie_id.'.'.$pathinfo['extension'];
		$base_directory= "../attachments/"; 
		$target = $base_directory.''.$new_name;
		$url = $new_name;
		$uploadOk=1; 
		$fileParts = pathinfo( $url );
		$extension = $fileParts['extension'];
			if($extension=="jpg" OR $extension=="jpeg" OR $extension=="JPG" OR $extension=="GIF" OR  $extension=="gif" OR $extension=="PNG" OR $extension=="png" OR $extension=="doc" or 
			$extension=="docx" or $extension=="pdf" OR $extension=="xls" OR $extension=="xlsx" OR $extension=="ppt" OR $extension=="pptx" OR $extension=="txt" OR $extension=="pub" OR $extension=="wps"
			or $extension=="bmp" OR $extension=="BMP")
			{
				$uploadOk = 1;
			} 
			else 
			{
				$uploadOk = 0;
				header("Location: ../project_badfile.php");
				exit();
			}
		
			
			if(!move_uploaded_file($_FILES['attachment_1']['tmp_name'], $target))  
			{
				header("Location: ../project_no_upload.php");
				exit();
			}
			else 
			{
			  
			$sql_10 = "insert into attachments (project_id, url) values ('$novie_id', '$url')";
				if(!$query_10=$mysqli->query($sql_10))
				{
					$err_10='your attachments info didn\'t get uploaded becasue:'
					. 'ERRNO: '
					.$mysqli->errno
					. 'ERROR: '
					.$mysqli->error
					. 'and the query itself looks like this: '
					.$sql_10
					.PHP_EOL;
					trigger_error($err_2, E_USER_NOTICE);
				}
			}
		}
		
		if(isset($_FILES['attachment_2'])&& !empty($_FILES['attachment_2']['name']))
			{
			$pathinfo_1 = pathinfo($_FILES['attachment_2']['name']);
			$new_name_1 = $pathinfo_1['filename'].'_'.$novie_id.'.'.$pathinfo_1['extension'];
			$base_directory_1 = "../attachments/"; 
			$target_1 = $base_directory_1.''.$new_name_1;
			$url_1 = $new_name_1;
			$uploadOk_1=1; 
			$fileParts_1 = pathinfo( $url_1 );
			$extension_1 = $fileParts_1['extension'];
			if($extension_1=="jpg" OR $extension_1=="jpeg" OR $extension_1=="JPG" OR $extension_1=="GIF" OR  $extension_1=="gif" OR $extension_1=="PNG" OR $extension_1=="png" OR $extension_1=="doc" or 
			$extension_1=="docx" or $extension_1=="pdf" OR $extension_1=="xls" OR $extension_1=="xlsx" OR $extension_1=="ppt" OR $extension_1=="pptx" OR $extension_1=="txt" OR $extension_1=="pub" OR $extension_1=="wps" or $extension_1=="bmp" OR $extension_1=="BMP")
				{
					$uploadOk_1 = 1;
				} 
				else 
				{
					$uploadOk_1 = 0;
					header("Location: ../project_badfile.php");
					exit();
				}
			 
				if(!move_uploaded_file($_FILES['attachment_2']['tmp_name'], $target_1))  
				{
				header("Location: ../project_no_upload.php");
				exit();
				}
				else 
				{
				  
				$sql_2 = "insert into attachments (project_id, url) values ('$novie_id', '$url_1')";
					if(!$query_2=$mysqli->query($sql_2))
					{
						$err_2='your attachments info didn\'t get uploaded becasue:'
						. 'ERRNO: '
						.$mysqli->errno
						. 'ERROR: '
						.$mysqli->error
						. 'and the query itself looks like this: '
						.$sql_2
						.PHP_EOL;
						trigger_error($err_2, E_USER_NOTICE);
					}
				}
			}
		}
		

Open in new window


If I try to upload one file at a time using the "attachment_1," no problems. If I try to upload two files at the same time using both "attachment_1" and "attachment_2," it doesn't work.

What am I doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

That will do it!

Thanks!
Thanks for the points and thanks for using E-E.  And best of luck with your project! ~Ray