title: trying to write to txt file with php and ajax post
body: <p>I am trying to save a string that is created dynamically based on the user's interaction with the web app that I'm creating. just a string. nothing special. I am using ajax to send the string up to the server, and it seems that it is getting as far as the file_put_contents function I am using, but it seems to go haywire. It makes the txt file, but it does not put anything in it, and it does not send back q, the variable that I have it echo back.</p>
  
  <p>Another weird thing is that when I try to write to said file with this </p>
  
  <pre><code>file_put_contents($putStringHere, $q);
  </code></pre>
  
  <p>I also tried this one:</p>
  
  <pre><code>file_put_contents($putStringHere, "$q");
  </code></pre>
  
  <p>The file always says that this happened:</p>
  
  <p>modified: Today, Now (last time I ran the function)</p>
  
  <p>Last Opened: Today, 5 minutes ago... last time I opened the file by hand</p>
  
  <p>This would make sense, except for the fact that the function above contains fopen, fmodify, fclose, or whatever they're called. And the modified set to the last time I ran the function... I am super confused on this one. anyone who can help, I will greatly appreciate it.</p>
  
  <p>ajax that sends string (yes, i made sure it was a string)</p>
  
  <pre><code>//ajax for saving changes
  function stylesheetBackup(str){
      var xmlhttp = new XMLHttpRequest();
      xmlhttp.open("POST","stylesheetBackupFile.php",true);
      console.log("q="+str);
      xmlhttp.send("q="+str);
  }
  </code></pre>
  
  <p>also tried ajax with</p>
  
  <pre><code>xmlhttp.open("POST","stylesheetBackupFile.php",true);
  xmlhttp.send();
  </code></pre>
  
  <p>php that I call with ajax</p>
  
  <pre><code>&lt;?php
  //get the q parameter from URL
  $q = $_POST["q"];
  $putStringHere = "savedStyleSheet.txt";
  //output the response
  echo $q;
  
  //save to a backup file
  file_put_contents($putStringHere, $q);
  ?&gt;
  </code></pre>