I'm attempting to upload a .csv file and then save the info in a table. I can do this using this code:
Code: Select all
<?php
$uploaddir = '/home/public_html/uploads/';
$uploadfile = $uploaddir . basename($_FILES['users']['name']);
$uploadfilename = basename($_FILES['users']['name']);
if (move_uploaded_file($_FILES['users']['tmp_name'], $uploadfile)) {
echo "<h2>Sucessful Upload</h2><p>File is valid, and was successfully uploaded.</p>";
} else {
echo "<p>Problem Uploading</p>";
}
include("/dbsetup.php");
$handle = fopen ('/home/public_html/uploads/users.csv', 'r');
while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE)
{
$query = "INSERT INTO users VALUES ('". implode("','", $data)
."')";
$query = @mysql_query($query);
}
?>1. I need the uploaded information to completely overwrite what's currently in the table - currently it's appending info to the stuff there (never had to do this before - do I empty the table somehow before inserting new stuff?)
2. One of the fields is a password - not sure how to fit in the MD5 conversion bit that I'd use with a normal update query.
Thanks in advance.