I am currently working on a web page where I want to run a python script on Button click event. My python script is working properly in terminal but I am not able to call the same script from the PHP page.
Below is the code for my PHP page.
<html>
<head>
<meta charset="UTF-8" />
</head>
<? php
print_r($_POST);
if (isset($_POST['ON']))
{
exec("sudo python /home/pi/Desktop/IOT/script5.py");
}
if (isset($_POST['OFF']))
{
exec("sudo python /home/pi/Desktop/IOT/script5a.py");
}
if (isset($_POST['1']))
{
exec("sudo python /home/pi/Desktop/IOT/script1.py");
}
?>
<form method="POST">
<button name="ON" value="Submit">turn On</button>
<button name="OFF">turn Off</button><br>
<button name="1">First</button><br>
</form>
</html>