Page 1 of 1

i need help!

Posted: Fri Feb 17, 2012 2:06 am
by makuletz27
i want to save the file in the database that the user upload.....

----flow-----

log in --- upload

but there's an error

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

but it save at the database....

Code: Select all

<?php
include 'db-connect.php';

if($_SERVER["REQUEST_METHOD"]=="POST"){
	$name = $_FILES['file']['name'];
	
	$extension = strtolower(substr($name, strpos($name, '.')+1));
	$tym_name = $_FILES['file']['tmp_name'];
	$type = $_FILES['file']['type'];
	$size = $_FILES['file']['size'];
	$max_size =  2097152;
	
	if(isset($name)){
		if(!empty($name)){
			if(($extension=='jpg'||$extension=='jpeg')&& $type=='image/jpeg' && $size<=$max_size){
				
				$location = 'upload/upload_files';
				if(move_uploaded_file($tym_name, $location."/".$name)){
					
					$sql = mysql_query ("INSERT INTO profile_photo (id,filename,size)"."VALUES('".$_SESSION['id']."','$name','$size')");
					mysql_query($sql) or die('Error: ' . mysql_error());
					echo "1 record added";						
				}else{
					echo "there's an error";
				}
			}else{
				echo "the file must be jpg/jpeg and must be less than 2mb ";
			}
		}else{
			echo "Please Choose a file. ";
		}	
	}	
}
?>

<html>
	<body>
		<form method="post" enctype="multipart/form-data">
			<input type="file" name="file"/><br>
			<input type="submit" name="submit"/>
		</form>

	</body>
</html>

Re: i need help! how can i insert the file in the database..

Posted: Fri Feb 17, 2012 6:11 am
by Celauran
How about you show us what you've tried, tell us where you ran into trouble, and we'll see what we can do to help. We're not here to write your code for you.