I'm trying to make a script that will take an uploaded CSV file specified by the user and replace into an existing table. I tested the syntax in PHPMyAdmin because it has the function so that you can insert data from a text file into a table. Here's the form:
Code:
<div id="body"><form action="parts.php?action=parts" enctype="multipart/form-data" method="post">
<div id="updates">
<div class="header">Install Parts Update</div>
Use the button below to select a file for upload.<br /><br />
<input name="MAX_FILE_SIZE" type="hidden" value="5242880" /><input name="partslist" type="file" /><br />
</div>
<div id="buttons">
<input name="submit" type="submit" value="Cancel" /> <input name="submit" type="submit" value="Install Update" />
</div>
</form></div>
Here's the PHP code:
Code:
// This isn't working. I can't understand why.
if( $_FILES['partslist']['name'] ) {
$sql_install = mysql_query( "LOAD DATA LOCAL INFILE '{$_FILES['partslist']['tmp_name']}' REPLACE INTO TABLE `ars_parts` FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\r'" );
if( $sql_install ) { $info = "Parts update installed."; }
else { $info = 'Failed to install parts update: ' . mysql_error() . '.'; }
}
Every time it tells me "Failed to install parts update: The used command is not allowed with this MySQL version." But it lets me upload with PHPMyAdmin! I copied and pasted the line that PMA gives me on a successful insert. There's probably something simple that I'm missing but I just can't figure it out. Any help would be appreciated.
Bookmarks