Jump to content

[SOLVED] updating passwords in a table by reading a file


cluce

Recommended Posts

I wrote a loop that reads a csv file which contains passwords for users in a table. and when I run my script, it reads the file fine and updates the passwords next to the appropriate user but it adds two little squares behind the passord. for example, password[][].  it looks something like that. does anybody know why this is?

 

my code does work but I post it here just to give a bigger picture of what im doing.

<?php
$counter = 1; //initialize counter

    include'db.php';

$filename = "pass.csv";
    $fp = fopen($filename, "r") or die("Couldn't open $filename");	

while (!feof($fp)) {


$line = fgets($fp, 1024);


$sql3 = "UPDATE employees SET password = '$line' WHERE EmployeeID = '$counter' LIMIT 1";
mysqli_query($mysqli, $sql3);

echo "$counter<br>$line<br>"; //echo output of each count*2
$counter++;  //adds 1 to counter
}
//}	
?>

<?php
$counter = 1; //initialize counter

    include'db.php';

$filename = "pass.csv";
        $file = file($filename);
        foreach ($file as $line) {
        	$sql3 = "UPDATE employees SET password = '$line' WHERE EmployeeID = '$counter' LIMIT 1";
        mysqli_query($mysqli, $sql3);

        	echo "$counter<br>$line<br>"; //echo output of each count*2
        $counter++;  //adds 1 to counter
}
?>

 

New line character, use file to read in the file (it puts it into an array split at the new line).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.