I'm working on learning PHP and I'm trying to essentially have the user enter input into two different text areas, and having the content downloaded into a single .txt file once they click the button. I know my code is extremely rough, I haven't found any solutions online for my specific case-scenario, but here it is:
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="./style.css" />
</head>
<div class="navbar">
<a href="adminIndex.html">Home</a>
<a href="adminResume.html">Resume</a>
<a href="adminProjects.html">Projects</a>
<a href="adminContact.html">Contact</a>
<a href="adminSocial.html">Social</a>
<a href="logout.html">Logout</a>
</div>
<body>
<label for="textbox">Professional Summary</label>
<textarea id="textbox"></textarea>
<label for="bio">Brief Biography</label>
<textarea id="bio"></textarea>
<input type="button" id="homebt" value="Submit" />
</body>
</html>
<?php
if (isset($_POST['submit'])) {
$text = $_POST['bio'];
print ($text);
$filename = 'index.txt';
$string = $text;
$fp = fopen($filename, "w");
fwrite($fp, $string);
fclose($fp);
header('Content-disposition: attachment; filename=test.txt');
header('Content-type: application/txt');
readfile('test.txt');
die;
}
Currently nothing happens when the button is clicked. The entire code is in a file called adminIndex.php, and I have Apache Web Server running to open the file in my browser for testing purposes. If anyone could potentially help me out with what I'm doing wrong, I'd really appreciate it!
Edit (made the following changes to the end of the HTML code):
<form name='form' method='post'>
<label for="textbox">Professional Summary</label>
<textarea id="textbox"></textarea>
<label for="bio">Brief Biography</label>
<textarea id="bio"></textarea>
<input type="submit" id="homebt" value="Submit" name="submit" />
</form>
</body>