PHP MySql Upload function - NEED HELP

OK, first of… I’m completely new to MySql and PHP!!
This is my “problem”… I need to let user upload files to a server, and when the file is uploaded onto the server i need to make an entry in the MySql DB with a link to the file that was just uploaded.

I’ve been looking around the internet for a couple of days now, and i’ve tried alot, but i can’t get it to work propperly. I’ve been able to split it up in two (2) parts, so first you upload the file, then you make the DB entry. But i would like to combine these two into ONE function.

This is the PHP i’ve got so far… (the one that doesn’t work. this is were i’ve tried to combine the to steps.)

STEP #1
<?php include(“dbconnect.php”)?>

<?php

$upload_dir = "../files/";
$size_bytes = 1024000;
$limit_file_type = "yes";
$allowed_file_type = array('application/pdf');

     if (!is_dir("$upload_dir")) {
 die ("Mappen ($upload_dir) finns inte!");
     }
     if (!is_writeable("$upload_dir")){
        die ("Mappen ($upload_dir) g&aring;r inte att skriva till, &auml;ndra Chmod till (777)");
     }

if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{
    $size = $_FILES['filetoupload']['size'];
    if ($size &gt; $size_bytes)
    {
        echo "Filen &auml;r f&ouml;r stor, den f&aring;r inte vara st&ouml;rre &auml;n $size_bytes bytes.";
        exit();
    }
    if (($limit_file_type == "yes") && (!in_array($_FILES['filetoupload']['type'],$allowed_file_type)))
    {
        echo"Du kan bara ladda upp PDF filer";
        exit();
    }
    $filename =  $_FILES['filetoupload']['name'];
    if(file_exists($upload_dir.$filename)){
        echo "Filnamnet $filename finns redan. Filens namn m&aring;ste vara UNIKT.";
        exit();
    }
    if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {

       echo "Filen &lt;a href=$upload_dir$filename class=r_link&gt;$filename&lt;/a&gt; laddades upp utan problem!
	&lt;p&gt;&lt;a href=ars_sub_stp2.php class=r_link&gt;Klicka h&auml;r f&ouml;r att g&aring; vidare&lt;/a&gt;";
       exit();

    }
    else
    {

        echo "Ett ov&auml;ntat fel uppstod! V&auml;nligen f&ouml;rs&ouml;k igen.";
        exit();
    }

}

?>

STEP #2

<?php
if(isset($_POST[‘submit’])) {
$file=$_POST[‘file’];
$year=$_POST[‘year’];
$sql = mysql_query(“INSERT INTO ars (file, year) VALUES (’<a href=…/…/files/$filename target=_blank><img src=…/…/images/pdfICO.jpg width=95 height=48 border=0> get file from $year</a>’);”);

echo ‘File was enterd into DB’;
}
?>

I know, it’s probably all wrong… like i said… just started this MySql PHP stuff :azn:

Thx to anoyone who has/and want’s to take the time to look at/try to help with this problem.