Weird PHP Behaviour or Stupid Mistake?
<p>I've written some pretty complex PHP apps using this feature, so I'm not sure what's happening here.</p>

<p>I'm currently writing an app that uses an online history to save content (via ajax get). The API I wrote to store the user's history to a file is extremely simple:</p>

<pre><code>$myFile = "./snhistory/".$_GET["uid"];
$stringData = urldecode($_GET["name"])."\n";
$file = fopen($myFile,"a");
fwrite($file,$stringData);
fclose($file);
</code></pre>

<p>This looks like the kind of code that adds the data found in <code>name</code> plus a new line to the end of a file, right? Well, that's not how PHP sees it. It adds one name, then when I run the code with a different name, it overwrites the first and only the second one appears. I've tried anything I could think of:</p>

<pre><code> file_put_contents($myFile,file_get_contents($myFile).$stringData);
</code></pre>

<p>And</p>

<pre><code> file_put_contents($myFile,$stringData,FILE_APPEND);
</code></pre>

<p>And </p>

<pre><code>fopen($myFile,"w");
fseek($file,0,SEEK_END);
</code></pre>

<p>And all produce the same behaviour. Is it something wrong with PHP or am I missing something here? I feel like if there was a problem in the code, the second thing I tried would have fixed it. But I'm not sure, which is why I'm asking everyone here.</p>

<p>I would really appreciate any help that could be provided. </p>

<p><strong>Edit:</strong> As per the answer, the problem with the strings was that they contained punctuation like <code>'</code> and, for some reason, the url encoding and escaping doesn't work. Read the answer's edit for the final answer.</p>
