I am learning the html/php basics and I want to record input to a txt file. It can be used for the MCU with NJ60 internal or external ethernet adapter, so we can record who was using the site and turning on, off the oven so he burned the house remotely or so on.
Here is the code as much as I have reached, but I dont know hot to connect it toghether. I can record with the php file, and the html file gives me what I need as a form, how to put the text in the form as what I need to record by the php file.
html file
php file
Here is the code as much as I have reached, but I dont know hot to connect it toghether. I can record with the php file, and the html file gives me what I need as a form, how to put the text in the form as what I need to record by the php file.
html file
Code:
<!DOCTYPE html>
<html>
<body>
<center>
<br><br><br>
<p>Please enter your somecontent!</p>
<form id="frm1" action="/action_test.php">
somecontent: <input type="text" name="somecontent" id="somecontent"><br>
<input type="button" onclick="myFunction()" value="Update">
</form>
<script>
function myFunction() {
var input = document.getElementById('somecontent'),
fileName = input.value;
if (fileName) {
Recorder('somecontent', fileName); // This is uncertain
} else {
alert('Please enter a somecontent!');
input.focus();
}
}
</script>
Code:
<?php
$filename = 'test.txt';
$somecontent = "asdasd";
// Let's make sure the file exists and is writable first. if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
?>
<center>
</body>
</html>