For the last two days I have been trying to get form data from my website written to a .txt file through php. The text file is one line of data, and I want to overwrite this data every time I write to the file. I have tried to incorporate my php with html, and also tried linking the html to the php file. I am new to php, and form data transfer.
OS = Raspberry pi Model B
Server = Apache 2 with php5 installed
Code Below (any help would be great)
(file name myform1.php) Stored in root server directory
[php]
<?php { $varName = $_POST['formName']; $fp = fopen("thermostat.txt", 'r+') or die("cant open file");; fwrite($fp,$varName); fclose($fp); exit; } ?>[/php]
(file name index.html) Stored in root server directory
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
<title>Full Control | Home Automation Made Easy</title>
<link rel="stylesheet" type="text/css" href="myhome.css"/>
</head>
<body>
</div>
<h1>Full Control Home Automation</h1>
</div>
<h2><em>Thermostat Control</em></h2>
<div>
<div id="settemp">
<h3>Desired Temperature</h3>
<form action="myform1.php" method="POST">
<p>
Set Desired Temperature<br>
<input type="text" name="formName" maxlength="10" />
</p>
<input type="submit" name="formSubmit" value="Submit" />
</form>
</body>
</html>
Thanks for any help in advance!