Skip to content
Advertisement

Session in While Loop PHP

JavaScript

In the upper code, I’m displaying my db table with a while loop

Each row has ID/LENGTH/NAME/VALUE/INPUT/BUTTON.

I get a value from the user, and I want to add it with the value in the same row and then update my db table.

GET method / displaying / SESSIONS and Update are done, but when I’m filling the input field the result saved in the last id.

I know that my code overwrites something and it can’t understand what input I filled up.

How can I solved it?

Advertisement

Answer

Don’t use sessions this way. Add a separate hidden input box to send the ID to the server for processing.

JavaScript

Now when you submit the form you will have 2 values, $_GET['row_id'] and $_GET['value']. Use the row_id to update the row you are trying to change.

If needed, you can still set the session values when you are processing the submitted form.

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