Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use variable with LOAD DATA INFILE MYSQL, PHP
    primarykey
    data
    text
    <p>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?</p> <p>Here is the code:</p> <pre><code>&lt;?php require_once('header2.php'); require_once('access.php'); ?&gt; &lt;head&gt; &lt;title&gt;Upload&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?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 "&lt;h1&gt;" . "File ". $_FILES['file']['name'] ." uploaded successfully." . "&lt;/h1&gt;"; } } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here is my table how it is uploaded with this code:</p> <p><img src="https://i.stack.imgur.com/1Hvi4.png" alt="enter image description here"></p> <p>Here is the php upload result with $dadate shown:</p> <p><img src="https://i.stack.imgur.com/gbpdk.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload