-1

When i upload a file to my databae i want it to get the user_id, but it is returning null.

I already have made some tests to check if its really returning null and it is once i upload.

It knows which user_id is logged on that upload page.

See my code:

<?php

if(isset($_POST['title']))
{
    //Check file type
    $ext = substr(strrchr(basename($_FILES['file']['name']), '.'), 1);
    if (!in_array($ext, $okExts))
    {
        echo "<p class=\"bad\">Formato Inválido.</p>";
    }
    else
    {
        $movePath = "../".$uploadPath . basename($_FILES['file']['name']); 
        $url = basename($_FILES['file']['name']);
        $title = mysql_escape_string($_POST['title']);
        $description = mysql_escape_string($_POST['description']);
        $user_id = $_GET['user_id'];

        if(move_uploaded_file($_FILES['file']['tmp_name'], $movePath)) 
        {
            //Update Fields
            $fileSQL = "INSERT INTO files (title, description, user_id, url) 
                      VALUES ('$title', '$description', '$user_id','$url')";

            mysql_query($fileSQL,$conn) or die('Error: ' . mysql_error());

            echo "<p class=\"good\">O Arquivo ".basename( $_FILES['file']['name'])." foi enviado.</p>";
        } 
        else
        {
            echo "Ocorreu um erro ao enviar o arquivo, por favor tente novamente!";
        }
    }
}
?>
user3483155
  • 27
  • 1
  • 2
  • 4

1 Answers1

0

Why should not you use $_POST['user_id']; whether you $_POST['title']. To get $_GET['user_id']; you should pass page.php?user_id=36525 with URL.

IshaniNet
  • 153
  • 10