Increment the scores in different text files
<p>If I want to store and increment the score of the players in a text file. Every round generates different text file. Here is the code:</p>

<pre><code>$string = '';
for ($i=0; $i &lt; 20; $i++) { 
 $d = rand(1,30) % 2;
$char = $d ? chr(rand(65,90)) : chr(rand(48,57));
$string .= $char;}
$ourFileName = $string.".txt";

$counter = file($ourFileName);

echo $counter;
if(strcasecmp($answer3,$answer4) == 0) 
{

$counter[0]++; // increase the counter by one

echo "&lt;h3 style='color:White; margin-left:600px;'&gt;  Player 2 score: &amp;nbsp; $counter[0] &lt;/h3&gt;";
echo " &lt;h3 style='color:White; margin-left:600px;'&gt;Well done, the correct answer is :  $answer3 &lt;/h3&gt;";


}
else
{
$counter[0]--; // increase the counter by one

echo "&lt;h3 style='color:White; margin-left:600px;'&gt; Player 2 score: &amp;nbsp; $counter[0]   &lt;/h3&gt;";
echo "&lt;h3 style='color:White; margin-left:600px;'&gt; The correct answer is : $answer3 &lt;/h3&gt;";


}

$fp = fopen($ourFileName , "w");
fwrite($fp , $counter[0]);
fclose($fp);
</code></pre>

<p>this code generates a file with random string but it doesn't increment the score and renders null. If I create a file with a specific name it works but I want the files to be with different names. Is there any problem in my code???</p>
