Skip to content
Advertisement

How to save file txt using html and php

i try to save textarea in html to file (“C:xampphtdocstest1one.txt”)

so i figure out i must use php too.

this php code, it work fine

$fp = fopen('one.txt', 'w');
fwrite($fp, 'edit me please');
fclose($fp);
?>

so how can i use html textarea to edit php ‘edit me please‘ to any text i wanna to edit, plus that i wanna to enable multi line which save in one.txt if i need to.

my html code

<!DOCTYPE html>
<html>
<head>
<title>Using innerHTML</title>
</head>

<body>

your one.txt write in textarea :

<br>
<textarea id="emp" rows = "20" cols = "90" name = "description"></textarea>
<br>

<p>
<input type="button" id="bt" value="Change Label Text" onclick="Onclicky()" />
</p>

</body>



<script language="javascript">
function Onclicky() {

/////function which will do work, idk?!////

}
</script>
</html>

Update #1 (try to add php inside html), but still not work no txt file data created.)

<html>
<body>


<form action="" method="post">
<textarea name="text"></textarea>
<input type="submit" value="edit" />
</form>

<?php
if(isset($_POST["text"]){
$fp = fopen('one.txt', 'w');
if(fwrite($fp, $_POST["text"])){
    echo "Edited";
}
fclose($fp);
}
?>


</body>
</html>

i’m still new, will be glade for your help :)..

Advertisement

Answer

You Need To know More About “Handle Form Using PHP”.

  • $_GET : collect form data.

html :

<form action="your_data.php" method="get">
Enter a Name: 

<br>
<textarea id="emp" rows = "20" cols = "90" name = "name"></textarea>
<br>

<input type="submit">
</form>

</body>
</html>

your_data.php :

<html>
<body>

your data :   
<?php
$fp = fopen('one.txt', 'w');
fwrite($fp, $_GET["name"]);
fclose($fp);
?>

</body>
</html>

to know more!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement