It is currently Wed Feb 08, 2012 5:19 pm

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Question regarding PHP and MySQL
PostPosted: Wed Oct 17, 2007 9:50 pm 
Offline

Joined: Wed Oct 17, 2007 9:41 pm
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 3:40 am 
Offline

Joined: Sun May 02, 2004 11:34 pm
Posts: 6500
Location: toronto, canada
what part wasn't working...

$_FILES['userfile1']['name'] should give you the name of the file

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to: