JAC JAC - 1 year ago 68
PHP Question

PHP change text in a div using a form

I have php file text.php in it i have

<div class="Text">Some text bla bla bla</div>

I have another file submit.php

in which i have a form

<textarea name="text" cols="30" rows="10"></textarea>
<input type="submit" value="Upload File">

So my question will be, how do i make the text change in text.php using my form from submit.php?


Answer Source

Your full submit.php:

if(isset($_POST['text'])) {
    file_put_contents('text.php','<div class="Text">'.$_POST['text'].'</div>');
<form action="submit.php" method="post">
<textarea name="text" cols="30" rows="10"></textarea>
<button type="submit">Save</button>

Hope you are aware of the consequences in keeping the text.php file in "php". Users can type any code inside PHP tags. Better keep that file html.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download