PHP, U in CRUD. Is it possible to edit DB from bootstrap Modal?

I am trying to work on a PHP project that connects to a sql database.

I am creating a lists of divs that has an edit and delete button. When I select the edit button I would like the have a form pop up in a Modal window in order to perform the edits.

On my page, when I select one of my edit buttons I use PHP ISSET($_GET[’?’]) and create a new variable and assign data from my database. In my MODAL I try and access the variable but get error that the variable is undefined.

I feel that the issue is that when the MODAL is added to DOM when the page loads initially the variable never gets set because ISSET($_GET[’?’]) has not been called yet by the edit button. Some sort of asynchronous issue.

Hope my question makes sense. Wondering if it is possible to get that to work?

Hello @MikeBeers,

It is possible to perform update operations in a bootstrap modal, but I don’t think it can be done in the way you’re trying it. PHP isn’t asynchronous, and it can’t handle things that happen in the browser after the page loads. PHP is 100% server side only. If you want the modal to be dynamic in the browser than that will have to involve JS.

So if you have a list of items that you want to edit the best way to do it would be to

  1. Add a data attribute to the button with the id of the element you want to edit
  2. Open the model with the form and use JS to populate the form with the appropriate data.
    • This could either be a call to an api endpoint to get the data as json
    • Or you can use an ajax call to straight up replace the form that is rendered on another page.
  3. Submit the form