so i am trying to change my current design for an IoT porject i am experimenting with. currently i am using "submit" as my button type but i don't like how the page refreshes. so i did some digging online and found that ajax was my solution using the "button" type. however i am very unfamiliar with jquery or ajax so im trying to do this.
currently this is my php function that captures the submit button.
if(isset($_POST['button']))
{
$id = $_POST['button'];
$sql = mysql_query("SELECT * FROM device WHERE Username = '".$_SESSION['Username']."' && DeviceID = '".$id."'");
$productCount = mysql_num_rows($sql);
if ($productCount > 0)
{
$row = mysql_fetch_array($sql);
$status = $row["Status"];
$et = "";
if($status == 1)
{
$et = "a";
$status = 0;
}
else
{
$status = 1;
}
exec("sudo python /var/www/html/light/script'".$id."''".$et."'.py");
mysql_query("UPDATE device SET Status = '$status' WHERE DeviceID = '$id'");
header( "refresh:0.01;" );
//ADD scripts here and also to capture data.
}
}
ignore the header(refresh) feature i was just trying to do a work around but nothing was satisfying my itch.
Any help or tips are greatly appreaciated
EDIT
also this is the button i have atm
<div class="col-md-2">
<button type="submit" name="button" id="button" value="'.$id.'" class="btn btn-default">Toggle '.$ddt.'</button>
</div>