I've been working on a new uploader for my website, and it works using sql so that a viewing page can be dynamically generated. However, I am having unexplained sql errors.
In my script, I have a line that inserts a row for the information on the upload, using a temporary hash so that the row can be revisited later in the code. The first problem I have is that the query won't work. I checked the error using mysql_error(), and it says I haven't selected a database (which is wrong).
The error also occurs later in the script, where the sql row is revisited.
Here is a link to the page:
http://knoxius.com/sites/test/upload/upl oad.php
Here is the code until the INSERT INTO query:
//MySql Info
mysql_connect('localhost','secret','secret');
//this is the hard part: the db is here, but it doesnt believe me
mysql_select_db('knoxius8_upload');
//Error Function - Remove Temporary Row
//This is for if an error occurs in the script: the temporary row is deleted and mysql is closed
function error($hash) {
$find_entry = mysql_query("DELETE FROM files WHERE filename='$hash'");
mysql_close();
}
//File Info
//all of the file info
$file = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_location = $_FILES['file']['tmp_name'];
$file_ext = explode('.',$file);
$file_ext = array_reverse($file_ext);
$file_ext = $file_ext[0];
//Temporary Row
$date = time();
$user_ip = $_SERVER['REMOTE_ADDR'];
$temp_hash = md5($file);
$insert = mysql_query("INSERT INTO files VALUES(NULL,'$temp_hash','$date','$user_ip')");
//put this here to test the query
if(!$insert) {
echo 'problem <br />';
echo mysql_error();
exit;
}
I really do not know what the problem is...hopefully someone can help? Thanks.