Hi-
I am trying to import data to a database via a CSV file. Everything is working just fine (yay!) but I need to convert one field (password) to md5 encoding so that it is stored in the database properly. As it is now, it's stored in the database in it's original form. Example, say the password is 'bluebird', it's stored as 'bluebird'.. I need it to be stored as md5(bluebird) which ends up as a (seemingly) random string.
I was trying to figure out a way to have this script stop at the third column, md5 it, then keep going like normal. But I can't figure out how to do it. Here's the import script I'm using (didn't write it myself, found it on another very helpful site!):
$fcontents = file ('./database2.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 alumni_data values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
Or if there is another, better way to import, I'm all ears. But, as I said, the import works great- I just need to modify one of the fields BEFORE it's imported.
Thanks in advance!