I'm trying to write a MySQL statement to insert information to a table:
$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."'
)";
Everything inserts correctly except for the $user
variable which echos out but doesn't get inserted and the same goes for $putFile
. Is there anything in this MySQL statement that I am doing wrong?
Thanks
full code here
<?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 us defined in pageCheck.php
Your issue is a scoping one. Within your saveFile()
function, $user
and $putFile
are not in scope.
See http://php.net/manual/en/language.variables.scope.php
You should consider passing them as arguments, eg
function saveFile($user, $file, $title) {
// etc
}
saveFile($user, $putFile, $_POST['title']);