I Am In A Trouble.
Accutally In a form in php (Username,Password) i want to set the password for each username. Mean
if($fh == "Harry") {
$password = "123456";
}
It Can Be Easily Create. But Problem is that i have total 500+ username. So Its Not possible by me, to set each username's password by the given method.
On of my a Friend, Created This By this method. And I found his username's password setted by this type.
"Harry":"12345","Biswas":"789456","garry":"56894"
So I wanted to create, Like This. So Please Tell Me. How Can I Create This ?
Create a lookup array for your data:
$str = '"Harry":"12345","Biswas":"789456","garry":"56894"';
$passwords = array();
foreach( str_getcsv( $str) as $entry) {
list( $name, $pw) = explode( ':', $entry);
$passwords[$name] = $pw;
}
Then, just use their name as the key to find their password:
$fh = "Harry";
echo $passwords[$fh]; // 12345
Assuming your data file looks like this "Harry":"12345","Biswas":"789456","garry":"56894"
and the data file name is userpass.txt
$data = file_get_contents("userpass.txt");
$records = explode(",", $data);
foreach ($records as $record) {
$record = preg_replace('/"/', "", $record);
$userpass = explode(":", $record);
//DO YOUR SQL STATMENT HERE
$sql = "INSERT INTO user (username, `password`) VALUES ('" . $userpass[0] . "','" . $userpass[1] . "')";
//execute query
}