Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting to a text file in PHP opens a new window
    primarykey
    data
    text
    <p>Ok, I've got a form and i've parsed all the data and i'm ready to write it to the file. I use the following PHP code (simplified):</p> <pre><code>$file = fopen("Data.txt","a"); fwrite($file,$_GET["InputText"]); fclose($file); </code></pre> <p>It writes just fine to the file but opens a new blank page. How do i stop it from doing that?</p> <p>Thanks for the help</p> <p>-Dave</p> <p>EDIT: No output generated by PHP. It just writes a line of text to a file. I am using a seperate file to hold my PHP code... &lt; form id="fmInput" action="IM.php" onsubmit="submitText()" ></p> <p>How else can i do that?</p> <p>EDIT2: Heres more of my code:</p> <pre><code>&lt;form id="fmInput" action="IM.php" onsubmit="submitText()"&gt; &lt;input type="text" name="fnInputText" id="iInputText"&gt; &lt;/form&gt; &lt;?php //IM.php $file = @fopen("IMData.txt","ab"); fwrite($file,$_GET["fnInputText"]); fwrite($file,"&lt;br&gt;"); fclose($file); ?&gt; </code></pre> <p>Now, when the user hits enter on the form, JS captures and processes (using the submitText function) then PHP writes it to a file, but then opens a blank browser...</p> <p>EDIT3: I'm guessing its a blank page being loaded in the same window because it's got this in the address bar "/IM.php?fnInputText="</p> <p>I dont want it to do that. I need it to write to the file without any interuption, so having PHP display anything after it runs is a deal breaker. Even if i have to have it reload the page that'd be better... It'll be marginally more time consuming as JS will have to reload the file again...</p> <p>I figured out how to read from a file using JS and the XMLHttpRequest but for the life of me i cant get JS to write to the file. I'd perfer to use JS as I know very little about PHP (which is probably aparent from this post ;D)</p> <p>My goal is this: page loads, JS reads in file and displays file on screen. User types in somthing, hits enter, JS adds that to screen and then [PHP or JS] writes data to file. repeat.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload