JAC JAC - 4 months ago 11
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

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


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

Thanks.

Answer

Your full submit.php:

<?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>
</form>

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.

Comments