I have the following script
<?php
// if file submitted
if($userfile) {
if(copy($userfile, "$basedir/bwdOnly/shipping/EXPORT.csv")) {
// count number in database now
$querycount1 = "SELECT count(*) FROM trackShipment";
$count1 = mysql_query($querycount1);
$cnt1 = mysql_result($count1,0);
// insert data into shipment database
$query = "LOAD DATA INFILE '$basedir/bwdOnly/shipping/EXPORT.csv' REPLACE INTO TABLE trackShipment FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\r\\n' (orderNumber,upsNumber)";
$result = mysql_query($query);
$affectedrows = mysql_affected_rows();
// count number in database now after submission
$querycount2 = "SELECT count(*) FROM trackShipment";
$count2 = mysql_query($querycount2);
$cnt2 = mysql_result($count2,0);
// show status
echo "<P>$affectedrows records were added to the shipping database<P>";
echo "<P>Before the update there were $cnt1 records and now there are $cnt2 records.<P>";
echo "OK WE GOT IT!";
echo "<P>SQL WAS<P> $query<P>";
} else {
echo "File not copied.";
die();
}
// end script
die();
}
// show form
echo <<<EOF
<form method="POST" action="$PHP_SELF" enctype="multipart/form-data">
Upload: <input type="file" size="40" name="userfile">
<input type="submit" value="Update Shipping">
</form>
EOF;
?>
It's uploading the file fine, however, the SQL won't execute. I can copy the SQL that I'm echoing out, run it in phpMyAdmin and it executes fine. I have no clue what's causing it not to execute in PHP.
Please note you see no mysql connection information because it's already set up in a file that is appended with the PHP ini file.
My table structure is as follows:
name - type - null - extra
trackID int(11) No auto_increment
orderNumber varchar(20) No
upsNumber varchar(25) No
shipTime timestamp(14) Yes NULL
Again, I don't think its anything with my table. I can copy the query I'm echoing out and run it in phpMyAdmin and it executes flawlessly.
Thanks in advance for any help.