0

I need to make a php web crawler and this part of the web crawler doesn't work. It should make a file where it shows the password from the corresponding email that is in email_list.txt and that is in my database

$fh = fopen('user_data.txt', 'w');
$con = mysql_connect("localhost","root","");
mysql_select_db("userdata", $con);

/* insert field values into data.txt */
$content = explode("\n", file_get_contents('email_list.txt'));
$content2 = implode(" ", $content);
$result = mysql_query(" SELECT `password` FROM `users` WHERE `email` = '' ");

while ($row = mysql_fetch_array($result)) {          
    $last = end($row);          
    $num = mysql_num_fields($result) ;    
    for($i = 0; $i < $num; $i++) {            
        fwrite($fh, $row[$i]);                      
        if ($row[$i] != $last)
           fwrite($fh, ", ");
    }                                                                 
    fwrite($fh, "\n");
}
fclose($fh);

i expected the password to be generated in the .txt file but its just empty

Hasta Dhana
  • 4,699
  • 7
  • 17
  • 26
Schef02
  • 11
  • 1
    mysql_* functions were *deprecated* in php5 and **removed** in php7. Use mysqli or PDO – treyBake Oct 03 '19 at 10:10
  • @treyBake is right, you should update to mysqli or PDO. Besides that, this query **$result = mysql_query(" SELECT `password` FROM `users` WHERE `email` = '' ");** would get only the passwords of the users that have email="", so maybe you don't have any and, it is not a good idea to store passwords as plain text, you can use php password_hash function – nacho Oct 03 '19 at 10:17
  • Possible duplicate of [Why shouldn't I use mysql\_\* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Dharman Oct 03 '19 at 10:56

0 Answers0