Jump to content

Recommended Posts

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";
      }
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.