0

データベースに挿入しようとし$useridていますが、ユーザー ID を挿入する代わりに 0 が挿入さecho $user['id'];れます。ユーザー ID が返されます。

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.';
    }
}
?>

$user['id'] 関数

  //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);
  }

$user の var_dump

array(20) { [0]=> string(2) "14" ["id"]=> string(2) "14" [1]=> string(4) "test" ["username"]=> string(4) "test" [2]=> string(128) "f94f06eac339c5c59685d008318b88cf74d047742cca202271a49ac90c44e0ca4e0953c57b5dcf589b3deeedd04a3d0807ba134c3e0cf0e371066e69ae92d22e" ["password"]=> string(128) "f94f06eac339c5c59685d008318b88cf74d047742cca202271a49ac90c44e0ca4e0953c57b5dcf589b3deeedd04a3d0807ba134c3e0cf0e371066e69ae92d22e" [3]=> string(14) "test@gmail.com" ["email"]=> string(14) "test@gmail.com" [4]=> string(14) "test@gmail.com" ["ppemail"]=> string(14) "test@gmail.com" [5]=> string(0) "" ["ip"]=> string(0) "" [6]=> string(1) "0" ["banned"]=> string(1) "0" [7]=> string(0) "" ["reason"]=> string(0) "" [8]=> string(1) "1" ["active"]=> string(1) "1" [9]=> string(8) "28127712" ["code"]=> string(8) "28127712" }
4

1 に答える 1

2

フィールドが数値である可能性があるため、代わりに文字列を指定するため ('$userid' のクエリ パラメータでユーザー ID を引用符で囲みます)、mysql は 0 を想定しています...

于 2012-05-20T03:03:41.117 に答える