Replacing array contents not working properly
1 post
Page 1 of 1
I'm doing a system that allows the user to express a vote depending on the button pressed. Currently you can express three types of voting. Each user is saved in a text file on a line, and the last three indices represent the status of the vote; if it corresponds to 0, then it means that the vote hasn't yet been given, otherwise corresponds to 1. The code that I made before performing a search within the file to see if the user has been found, then you save the line where it's found and I go to work on it. In particular I split the row and save the indices of an array. At this point, unless the array to a new variable $line and modify its six index with "1", so I'll have an array with a score performed. I use str_replace to replace the old array to the new file. The problem? Are replaced all the "0" and not just the last one as I have noted, in particular I find a line like this:
user; Heisenberg@gmail.com; Heisenberg; 123; yes; 1; 1; 1;
as if this were not enough, they are replaced indices of all other users in the file and not only those user found. How is this possible?
user: is the user rank
Heisenberg@gmail.com: email
Heisnberg: is the username
yes: activation status
0: first votation type
0: second votation type
0: third votation type
user; Heisenberg@gmail.com; Heisenberg; 123; yes; 1; 1; 1;
as if this were not enough, they are replaced indices of all other users in the file and not only those user found. How is this possible?
Code: Select all
Here is the row file example: user;Heisenberg@gmail.com;Heisenberg;123;yes;0;0;0;$handle = fopen("utenti.txt", "r");
$file = file_get_contents("utenti.txt");
$count = 0;
if($handle)
{
while(($lines = fgets($handle)) !== false)
{
$count++;
if(strpos($lines,$_GET['email']) !== false) //email found
{
$line = $temp[$count] = explode(";", $lines); //user who voted
$line[6] = "1"; //index update
print_r($temp[$count]);
echo "<br>";
print_r($line);
$disable_consulta_provinciale = str_replace($temp[$count], $line,$file);
$temporary_file = fopen("utenti_temp.txt", "w+");
fwrite($temporary_file, $disable_consulta_provinciale);
fclose($handle);
fclose($temporary_file);
}
else
{
fwrite($handle, $file);
fclose($fo);
}
}
unlink("utenti.txt");
rename('utenti_temp.txt','utenti.txt');
user: is the user rank
Heisenberg@gmail.com: email
Heisnberg: is the username
yes: activation status
0: first votation type
0: second votation type
0: third votation type
I'm in the empire business.
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023