I have been reading through various questions relating to this, and thanks to a general lack of programming knowledge despite my best efforts I have not been able to make this work. Here are the questions I was looking at:
Update text file on button click
How to edit the contents of a file on button click? PHP?
And here is the code I am trying to use.
<h2>Click</h2>
<form action="" method="post">
<button name="on" class="on">ON</button> <button name="off" class="off">OFF</button>
</form>
<?php
if(isset($_POST['on']))
{
$file = 'LED.txt';
$previous = file_get_contents($file);
file_put_contents($file, '1');
}
?>
<?php
if(isset($_POST['off']))
{
$file = 'LED.txt';
$previous = file_get_contents($file);
file_put_contents($file, '0');
}
?>
I have no idea what I am doing wrong, if anyone could take a look I would be very grateful.
EDIT: I ended up using a different method to solve my problem, but thank you for your help. I checked back after finding a solution, but your fix would have worked too George. Thanks everyone.