What I am trying to do is,
Open the word file, read a line, convert it to md5, write to db if its not already there(both word and encrypted string)
For some reason, it doesnt work.
$file = fopen("list.txt", "r");
while (!feof($file))
{
$word = fgets($file);
$word = mysql_real_escape_string($word); // to prevent injections
$md5string = md5($word);
//check if in DB
$check = mysql_query("SELECT id FROM table WHERE word='$word'") or die(mysql_error
());
if (mysql_num_rows($check) > 0)
{
} //Nothing to do.
else
{
$write = mysql_query("INSERT INTO table (word, md5string) VALUES ('$word','$md5string')") or
die(mysql_error());
}
}
It is making the hashes and storing everything write, but the hashes thats made arent right.
Any idea whats wrong in my code?
Fix : I mysql_real_escaped the string before hashing and that was where I was wrong.
$word = trim(fgets($file));
$md5string = md5($word);
$word = mysql_real_escape_string($word); // to prevent injections`
ADD : I just corrected my script using the suggestions I got from here and found out that
Md5ecnrypter.com is doing it wrong.
They are escaping the string before hashing. How lame. Just checked other sites to see SO suggestions were right.