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
var_dump($insert);and show here (and since now always check the real sql generated, not the source php code)vle.files(id,time,fileLocation,title,user) VALUES (NULL, UNIX_TIMESTAMP(), '', 'blah3', '')"mysql_real_escape_string()? Docs: Note: A MySQL connection is required before usingmysql_real_escape_string()otherwise an error of level E_WARNING is generated, and FALSE is returned. If link_identifier isn't defined, the last MySQL connection is used.$userand actually run the query?$putFile&$userto the globals