Need help with PHP upload script

Discussion in 'Programming & Scripting' started by Ricochet606, Dec 30, 2008 with 0 replies and 104 views.

  1. Ricochet606

    Ricochet606 Newbie

    Messages:
    1
    Ratings:
    0
    I am trying to create a upload script that uploads a file and also puts the file into a database, im still working on adding a few things but so far im getting this error:

    The file has been uploadedError: 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 ' upload/test.txt)' at line 3

    This is my code:

    PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>File Uploaded</title>
    </head>
    <body>
    <?php 
    $target 
    "upload/"
    $target $target basename$_FILES['uploaded']['name']) ; 
    $ok=1
    $filename $_POST['uploaded'];

    //This is our size condition 
    if ($uploaded_size 67108864

    echo 
    "Your file is too large, our server has a limit on uploads of 64mb.
    "

    $ok=0


    //This is our limit file type condition 
    if ($uploaded_type =="text/php"

    echo 
    "No PHP files
    "

    $ok=0


    //Here we check that $ok was not set to 0 by an error 
    if ($ok==0

    Echo 
    "Sorry your file was not uploaded"


    //If everything is ok we try to upload it 
    else 

    if(
    move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 

    echo 
    "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded"
    $con mysql_connect("localhost","<username>","<password>");
    if (!
    $con)
    {
    die(
    'Could not connect: ' mysql_error());
    }
    mysql_select_db("<database>"$con);
    $sql="INSERT INTO uploads (filename, location)
    VALUES
    (
    $filename$target)";
    if (!
    mysql_query($sql,$con))
    {
    die(
    'Error: ' mysql_error());
    }
    else 

    echo 
    "Sorry, there was a problem uploading your file."


    }
    ?>
    </body>
    </html>
    Thanks for any help! :smile: