0

I have the following code, which correctly inserts data into the mysql database, however when I upload the file, that particular file will never contain a certain column called 'date' which exists in the mysql table. I would like to put it in with each row... So Basically, how do I make the last column the variable $dadate?

Here is the code:

<?php
require_once('header2.php');
require_once('access.php');
?>
<head>
<title>Upload</title> 
</head>
<body>
<?php
$filedir = addslashes($_FILES['file']['tmp_name']);
$dadate = $_POST['datadate'];
echo $dadate;
if (isset($_POST['submit'])) {
$sql="LOAD DATA LOCAL INFILE '$filedir' INTO TABLE employeehourstest FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 18 LINES (@dummy, @dummy, @dummy, @dummy, employeeid, @dummy, @dummy, paycode, @dummy, @dummy, @dummy, employeehours, @dummy, @dummy, @dummy, @dummy, @dummy, @dummy, @dummy, @dummy)";
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if ($result) {
echo "<h1>" . "File ". $_FILES['file']['name'] ." uploaded
successfully." . "</h1>";
}
}
?>
</body>
</html>

Here is my table how it is uploaded with this code:

enter image description here

Here is the php upload result with $dadate shown:

enter image description here

4
  • will you echo the $_POST['datadate'] and post result it might be helpful to answer also show the text present in that file to help you Commented Dec 10, 2013 at 5:22
  • will you show the file content of that csv Commented Dec 10, 2013 at 5:29
  • Add this to the end of LOAD DATA query SET workdate = $dadate see more info here dev.mysql.com/doc/refman/5.1/en/load-data.html Commented Dec 10, 2013 at 5:29
  • Please mark it as useful answer Commented Dec 10, 2013 at 7:46

1 Answer 1

1

Add this to the end of LOAD DATA query

SET workdate = $dadate 

see more info here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.