Page 1 of 1

Image upload

Posted: Fri Aug 22, 2008 6:58 am
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";
}


?>

Re: Image upload

Posted: Fri Aug 22, 2008 8:32 am
by onion2k
Your SQL is completely wrong. Read a tutorial about how to do inserts - http://beginner-sql-tutorial.com/sql-in ... tement.htm