Skip to content
Advertisement

How to POST from php table generated by mysql select when toggle btn in row is clicked?

I have a PHP page that retrieves data from a MYSQL select statement to populate 8-12 rows of a HTML table. Each row has a server name and a status represented by a bootstrap toggle switch for either condition on or off. When the toggle is changed, I want to POST the servername and desired state for that server to action.php. I was able to use some AJAX scripts I found to get the POST info to change the condition from 1 to 2, but only for the last row. I have not be able to figure out how to get the servername for each row to the script. How can I achieve this?

JavaScript

My attempt at ajax. This will POST to the desired page for the last row only and only if toggle is checked (condition1).

JavaScript
JavaScript

Advertisement

Answer

Inside the while loop you have:

JavaScript

which is why the last one is only picked up.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement