i need help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
makuletz27
Forum Newbie
Posts: 11
Joined: Fri Feb 17, 2012 1:53 am

i need help!

Post 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>
Last edited by makuletz27 on Sat Feb 18, 2012 7:10 am, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

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