title: MySQL Inserts 0 instead of variable value
body: <p>I'm trying to insert <code>$userid</code> to my database but instead of inserting the user id it inserts 0. When I <code>echo $user['id'];</code> it returns the user id.
      
  
  <pre><code>if (!empty($_FILES)) {
      // Validate the file type
      $userid = trim(sanitize($user['id'])); //GOD DAMMIT HELP HERE
      $fileTypes = array('jpg', 'jpeg', 'gif', 'png', 'rar', 'zip', 'exe'); // File extensions
      $fileParts = pathinfo($_FILES['Filedata']['name']);
      $ext = trim(sanitize($fileParts['extension']));
      $file_name = trim(sanitize($_FILES['Filedata']['name']));
      $file_size = trim(sanitize(format_bytes($_FILES['Filedata']['size'])));
  
      if (in_array($fileParts['extension'],$fileTypes)) {
          mysql_query("INSERT INTO files (userid, name, ext, size) VALUES ('$userid', '$file_name', '$ext', '$file_size')"); //Upload the file and add to MySQL
          $fileid = mysql_insert_id();
          move_uploaded_file($_FILES['Filedata']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/uploads/$fileid." .$fileParts['extension']);
          echo '1';
      } else {
          echo 'Invalid file type.';
      }
  }
  ?&gt;
  </code></pre>
  
  <p>$user['id'] function</p>
  
  <pre><code>  //Use $user['value'] to retrieve data
    if ($_SESSION['username'] != null) {
      $u_query = mysql_query("SELECT * FROM users WHERE `username` = '$_SESSION[username]' LIMIT 1");
      $user = mysql_fetch_array($u_query);
    }
  </code></pre>
  
  <p>var_dump of $user</p>
  
  <pre><code>array(20) { [0]=&gt; string(2) "14" ["id"]=&gt; string(2) "14" [1]=&gt; string(4) "test" ["username"]=&gt; string(4) "test" [2]=&gt; string(128) "f94f06eac339c5c59685d008318b88cf74d047742cca202271a49ac90c44e0ca4e0953c57b5dcf589b3deeedd04a3d0807ba134c3e0cf0e371066e69ae92d22e" ["password"]=&gt; string(128) "f94f06eac339c5c59685d008318b88cf74d047742cca202271a49ac90c44e0ca4e0953c57b5dcf589b3deeedd04a3d0807ba134c3e0cf0e371066e69ae92d22e" [3]=&gt; string(14) "test@gmail.com" ["email"]=&gt; string(14) "test@gmail.com" [4]=&gt; string(14) "test@gmail.com" ["ppemail"]=&gt; string(14) "test@gmail.com" [5]=&gt; string(0) "" ["ip"]=&gt; string(0) "" [6]=&gt; string(1) "0" ["banned"]=&gt; string(1) "0" [7]=&gt; string(0) "" ["reason"]=&gt; string(0) "" [8]=&gt; string(1) "1" ["active"]=&gt; string(1) "1" [9]=&gt; string(8) "28127712" ["code"]=&gt; string(8) "28127712" }
  </code></pre>