I currently am trying to learn a bit of HTML and PHP just for fun and am struggling to figure out how to use a button rather than a form in HTML to post to PHP.
This is one place I want to use it for a little ESP_8266 project.
if (isset($_POST['toggle_LED'])) {
$sql = "SELECT * FROM LED_status;";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
if($row['status'] == 1){
$update = mysqli_query($conn, "UPDATE LED_status SET status = 0 WHERE id = 1;");
}
else{
$update = mysqli_query($conn, "UPDATE LED_status SET status = 1 WHERE id = 1;");
}
}
Currently it toggles using this form:
<form method="post" id="LED" enctype="multipart/form-data">
<input id="submit_button" type="submit" class="button" name="toggle_LED" value="Toggle LED" />
</form>
What I would like to achieve is to use a button rather than a form so that the form can NOT resubmit and change the toggle status. I have tried using a "button onclick" and then having a <script>
that names a function with what I want it to do within that function but I cant seem to get that to work either.