Original: I am trying to make the PHP get the input that was put into the text box and write it to name.txt. I am also getting an error message that says "Expected tag name. Got '?' instead." on line 6.
<html>
<body>
<p>Enter name here:</p>
<input type="text" id="name"/>
<button onclick="[activate PHP]">Enter</button>
<?php
$fp = fopen('name.txt', 'w');
fwrite($fp, '[name entered]');
fclose($fp);
?>
</body>
</html>
I am not familiar with PHP, so please explain what your fixed code does when you answer.
New: This was made by @Vlad Gincher. The problem is, the code is not creating a .txt file, which leads me to believe that the PHP is executing as soon as the page loads. Is there a way to activate the PHP when the form is submitted?
<?php
if(isset($_POST["textareaValue"])) {
$fp = fopen('name.txt', 'w');
fwrite($fp, $_POST["textareaValue"]);
fclose($fp);
}
?>
<html>
<body>
<p>Enter name here:</p>
<form method="post">
<input type="text" id="name" name="textareaValue" />
<input type="submit" value="Enter" />
</form>
</body>
</html>
Again, I am inexperienced with PHP, it could be an error of mine.