Skip to content
Advertisement

How do I change a database entry when I enter text into an input?

The logic is this: the text is displayed from the database, next to it there is a box to enter, after you enter text and click on the link ‘edit’ record in the database should change. I did it only if the text is static. Everything works. But I need to take text from input. How do I do that? Can you please help me?

I added the ‘hidden input’ because I’ve seen similar solutions with it, but I can’t get the values.

JavaScript

wall.php:

JavaScript

Advertisement

Answer

Using GET to update records in a db is not a good idea. A GET request can easily be modified to affect other records, it can be bookmarked, shared and more. The generally accepted method for updating records is to use POST – which can, in theory, be used in conjunction with GET if it is really important to pass variables that way(such as modifying the form action)

The original code is vulnerable to SQL injection so when that vulnerability exists in conjunction with GET requests you are not far from problems. The following tries to mitigate risks by using POST in combination with “Prepared Statements” – the comments made through the code should offer further insight

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