我正在尝试编写一个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'>";
}
?>
$user我们在页面检查中定义.php
您的问题是一个范围界定的问题。在saveFile()
函数中,$user
和$putFile
不在范围内。
请参阅 http://php.net/manual/en/language.variables.scope.php
您应该考虑将它们作为参数传递,例如
function saveFile($user, $file, $title) {
// etc
}
saveFile($user, $putFile, $_POST['title']);