Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Store input in .txt file and output to html page
    primarykey
    data
    text
    <p>Using PHP I want to store user input from an html page in a .txt file and output that user input onto the same page.</p> <p>However, nothing is showing up in either the .txt file or on the page div.</p> <p><strong>IN ADDITION:</strong> I'd like to have each new message display on a new div, I know this is somewhat of a different question, but I figured it could be related.</p> <p>Any ideas on why this isn't working?</p> <p><strong>HTML:</strong></p> <p>The form itself:</p> <pre><code>&lt;textarea name="msg" rows="5"&gt;&lt;/textarea&gt; &lt;form id="post" name="post" action="storeText.php" method="post"&gt; &lt;input class="button" type="submit" value="POST!"/&gt; &lt;/form&gt; </code></pre> <p>Where I want to output on the same html page:</p> <pre><code>&lt;div class="menuItem" &gt; &lt;?=$msg?&gt; &lt;/div&gt; </code></pre> <p><strong>PHP:</strong></p> <p>storeText.php</p> <pre><code>&lt;?php $filename = 'posts.txt'; $msg = (isset($_POST['msg']) ? $_POST['msg'] : null); // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $msg) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($msg) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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