First off, hello everyone.. My first post..
I am working on a form in PHP that uses a MySQL DB. Part of my form contains some text files, the second part is a file upload area. I have mixed some code together so that on submit it populates the DB with data from the text fields and then uploads the files to their locations.. My issue is, I would also like to take the file name from the upload box (not the entire path, just the file.extention) and place that information into a field in the DB as well. I have tried submitting the upload field name as text to the DB but that did not work.. Any ideas? Here is that section of code..
Code:
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO itissues (name, `date`, computer, problem) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['date'], "text"),
GetSQLValueString($_POST['computer'], "text"),
GetSQLValueString($_POST['problem'], "text"));
mysql_select_db($database_helpdesk, $helpdesk);
$Result1 = mysql_query($insertSQL, $helpdesk) or die(mysql_error());
$insertGoTo = "records.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
// File Upload Code
$uploaddir = 'uploads/flow/';
$uploadfile = $uploaddir . basename($_FILES['userfile1']['name']);
$uploaddir2 = 'uploads/fac/';
$uploadfile2 = $uploaddir2 . basename($_FILES['userfile2']['name']);
$uploaddir3 = 'uploads/bit_maps/';
$uploadfile3 = $uploaddir3 . basename($_FILES['userfile3']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile1']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
if (move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
if (move_uploaded_file($_FILES['userfile3']['tmp_name'], $uploadfile3)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
}
Thanks for any help!
Craig