brainstorm Posted June 29, 2009 Share Posted June 29, 2009 Hi all, So far, I've gotten the following code to work just fine to INSERT new data into the DB. However, when I change things up a bit by adding the "UPDATE" function instead of the "INSERT" function, it gives me an error. Any Help is much appreciated! I'm trying to update the same clients with new info. Here's what I have so far... Code for file upload to directory on server: <?php if ($_REQUEST[completed] != 1) { ?> <b>Please upload Your .CSV file to update the Database.</b><br> <form enctype=multipart/form-data method=post> <input type=hidden name=MAX_FILE_SIZE value=1500000> <input type=hidden name=completed value=1> Choose file to send: <input type=file name=mailfile> and <input type=submit></form> <?php } else { ?> <br /><br /><b>Excel file successfully uploaded!</b> <?php } ?> Script to insert the data once the file has been uploaded: <? include 'dbc.php'; /// first get a mysql connection as per the FAQ $fcontents = file ('users.csv'); /// expects the csv file to be in the same dir as this script for($i=0; $i<sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode(',', $line); ///if your data is comma separated /// instead of tab separated, /// change the '\t' above to ',' $sql = "insert into users values ('". implode("','", $arr) ."')"; mysql_query($sql); echo $sql ."<br>\n"; if(mysql_error()) { echo mysql_error() ."<br>\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/164151-updating-multiple-rows-in-mysql-with-a-csv-file-import-help/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.