Hi all,
I'm writing a little music poll program.
I use a text file to keep the music names and the number of votes just
like this:
[FONT=courier new]
Soulmagic - Soulmagic |1
Simply Red - Fake |1
Sting - Send Your Love |4
Moloko - Forever Love |3
[/FONT]
and the following function where I input the line number where the music
is:
function vote($answer){
global $datafile; //file with the music list
If (!empty($answer)) {
$line=file("$datafile");
$regist=explode("|",$line[$answer]);
$regist[2]++;
$line[$answer]=implode("|", $regist);
$line[$answer]=$line[$answer]."\r\n";
ignore_user_abort(true);
$file = fopen($datafile, 'w+b');
if ($file){
if (flock($file, LOCK_EX)){
flock($file, LOCK_UN);
$i=0;
do{
fwrite($file,$line[$i],strlen($line[$i]));
$i++;
}while($i<count($line));
} else echo "Could not lock file '$datafile'";
fclose($fich);
} else echo "Could not open file '$datafile'";
ignore_user_abort(false);
} else echo "No answer!";
}
The problem is that instead of getting
[FONT=courier new]
Soulmagic - Soulmagic |1
Simply Red - Fake |1
Sting - Send Your Love |5
Moloko - Forever Love |3
[/FONT]
when the $answer is 2 I get
[FONT=courier new]
Soulmagic - Soulmagic |1
Simply Red - Fake |1
Sting - Send Your Love |4
|1
Moloko - Forever Love |3
[/FONT]
and it's driving me mad!!!
I'm using Apache running on windows filesystem.
Can anybody please help me undersanting what am I doing wrong?
Many thanks in advance and sorry for the long post.
Bruno