|
updating every row with random password script
Hey. Im trying to get a lot of a membership script finished, and theres a few things still need doing. This part im having problems with. Ive imported 750 records from a CSV file to an SQL database. These records hae been assigned random usernames and passwords. However, the passwords need to be MD5'd. So what I need to do is add an md5'd password to every user in the database, and email each individual their own password (the non-md5 one). The problems im haing is that i can never get it to work properly. It either updates everyone with the exact same password, or it updates 1 person, or it doesnt do anything. Please help!
I need some sort of loop to run the update query in, make any random password, add the password in MD5 form to the first record, email the non md5 password to that records email, and repeat the loop for the next record, producing a new unique password. The records dont have any type of auto_increment ID, so it will need to be done some other way. Any ideas?
I currently have the following, but theres no loop or anything to add a unique password to eeach record in the table
[code:1:d67bcc65a1]
<?php
include("database.php");
$randpass= rand();
$query = "UPDATE users SET password = md5('$randpass') "
$query2 = "SELECT * FROM users";
$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());
while ($row = mysql_fetch_array($result2)) {
mail($row["email"],"password $pass username $username)
}
?>
[/code:1:d67bcc65a1]
That code updates every record with the same password. i need it to update every record in turn with an individual password, and email that person right after it updates with their non-md5'd password.
|