I'm having a bit of trouble with this code, it is simply displaying the ambigious error (better than a blank screen). I'm unsure what is wrong with it. it is part of a webpage that uploads images and saves the information/description etc. to a database on mysql. any help would be tremendously appreciated.
<?php
$counter = 1;
//number of files to allow for
if (isset($_POST['submitted'])) { //Handle the form.
require_once ('mysql_connect.php');
//connect to database
for ($i = 0; $i < $counter; $i++) { //handle each uploaded file.
//create index names to refer to the proper upload and description
$filename = 'upload' . $i;
$description = 'description' . $i;
//check for a file.
//if (isset($_FILES[$filename]) &&($_FILES[$filename]['error'] !=4)) {
if (isset($_FILES[$filename]) or($_FILES[$filename]['error'] !=4)) {
//check for description (not needed)
if (!empty($_POST[$description])) {
$d = "'" . escape_data($_POST
[$description]) . "'";
} else {
$d = 'NULL';
}
//add record to database
$query = "INSERT INTO uploads(file_name, file_size, file_type, description) VALUES ('{$_FILES[$filename]['name']}',{$_FILES[$filename]['size']},'{$_FILES[$filename]['type']}', $d)";
$result = mysql_query ($query);
if($result) {
//return the upload_id from the database
$upload_id = mysql_insert_id();
//move file over
if (move_uploaded_file($_FILES[$filename]['tmp_name'], "uploads/$upload_id")) {
echo 'File number ' . ($i + 1) . 'has been uploaded.';
} else { //file could not be moved
echo 'could not move' . ($i + 1) . '.';
//remove the record from the database
$query = "DELETE FROM uploads WHERE upload_id = $upload_id";
$result = mysql_query($query);
//add more error reporting unneccesary
}
} else { //if query did not run ok
echo 'Your submission did not get uploaded, due to an ambigious system error.';
}
} //end of if(isset($the_file)...
} //end of FOR loop
mysql_close(); //close database
} //end of the main submit conditional
?>
<form enctype="multipart/form-data" action="add_file.php" method="post">
<fieldset><legend align="center">Select a JPEG (.jpg) or a GIF (.gif) image to be uploaded from your computer (3MB max).</legend>
<input type="hidden" name="MAX_FILE_SIZE" value="3145728" />
<?php
echo 'File <input type="file" name="upload' . $i . '" />
<br><br>
Description <textarea name="description' . $i . '" cols="50" rows="5"></textarea>';
?>
</fieldset>
<input type="hidden" name="submitted" value="TRUE" />
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
</form>