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
}
//}	
?>

Link to comment
Share on other sites

<?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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.