我正在尝试插入$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" }