-2
我想寫一個MySQL語句插入信息表:MySQL不會插入變量
$insert = "INSERT INTO `vle`.`files`
(`id`, `time`, `fileLocation`, `title`, `user`)
VALUES (
NULL,
UNIX_TIMESTAMP(),
'".mysql_real_escape_string($putFile)."',
'".mysql_real_escape_string($_POST['title'])."',
'".$user."'
)";
一切正確插入除了$user
變量,回聲了,但沒有得到插入$putFile
也是如此。這個MySQL聲明中有什麼我做錯了嗎?
感謝
完整的代碼在這裏
<?php require_once('Connections/localhost.php');
include('pageCheck.php');
include('adminCheck.php');
function saveFile(){
global $_FILES, $_POST;
$insert = "INSERT INTO `vle`.`files`
(`id`, `time`, `fileLocation`, `title`, `user`)
VALUES (NULL, UNIX_TIMESTAMP(), '".mysql_real_escape_string($putFile)."', '".mysql_real_escape_string($_POST['title'])."', '".$user."')";
mysql_query($insert);
var_dump($insert);
}
$putFile = "files/".basename($_FILES['uploadedFile']['name']);
if(move_uploaded_file($_FILES['uploadedFile']['tmp_name'], $putFile)){
saveFile();
echo"File has been uploaded, Redirecting to file list now...";
//echo"<meta http-equiv='refresh' content='3;url=dashboard.php'>";
}else{
echo"Unable to upload file, Returning to dashboard...";
//echo"<meta http-equiv='refresh' content='3;url=dashboard.php'>";
}
?>
$用戶我們pageCheck.php定義
'的var_dump($插入);'這裏顯示(和現在以來始終** **檢查所產生的實際的SQL ,而不是源代碼) – zerkms 2012-04-18 03:41:36
string(122)「INSERT INTO'vle'.'files'('id','time','fileLocation','title','user')VALUES(NULL,UNIX_TIMESTAMP() ,'','blah3','')「 – Ciaran 2012-04-18 03:45:39
這是你的問題,'$ putFile'和'$ user'是空的(或未定義)。 [啓用錯誤報告](http://stackoverflow.com/a/10135983/283366)將產生更多信息。 – Phil 2012-04-18 03:46:26