Image upload

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
grahamne
Forum Newbie
Posts: 6
Joined: Mon Jun 16, 2008 2:29 pm

Image upload

Post by grahamne »

Image uploads to correct folder yet the query for insertion to a database does not seem to work

<?php
session_start();
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{

if (file_exists("path" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"profile/" . $_FILES["file"]["name"]);

$path="path blah blah" . $_FILES["file"]["name"];
$session=$_SESSION['user'];

$sql="insert into picture SET user_id='$session'";
if(@mysql_query($sql))
{
echo 'works';
}
else
{
echo 'dont work';
}

// header('blah blah');

}
}
}

else
{
echo "Invalid file";
}


?>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Image upload

Post by onion2k »

Your SQL is completely wrong. Read a tutorial about how to do inserts - http://beginner-sql-tutorial.com/sql-in ... tement.htm
Post Reply