I’m not saying I know whats wrong, just suggesting how you isolate WHERE your code is going wrong, debugging you might say.
Try this:
Put your sql statement into a variable, then echo it onto the screen, copy it into whatever you use to manage your database and check the results actually bring something from your db.
You can debug your code. What you basically do is discover how your code is working, instead of assuming how it is working.
You should check the values of your variables. A good way to do this is by using var_dump(). The value should be what you expect. This includes stuff like your sql query. Assign the string to a variable so that you can echo it, and see what it looks like after the variables are expanded.
Check conditional statements too. For example, if statements, and loops. You can echo something inside of them to see if the block of code is ever actually run. For example
if ($foo) {
echo "entering the if(foo) block'"
}
For debugging an sql query, you might want to use something other than php. Like, phpmyadmin for example. You can just cut and paste the sql query to test the results.
At some point, you will come across a condition, or maybe a value that wasn’t what you expected. If your approach this strategically, you can eliminate large amounts of code as being suspect very quickly, and narrow down to your problem area in short time.
Okay, now I know the problem, but I’m unsure whether this is because I am doing something wrong. The code that I wrote above basically produces a list of all rows in the table as input boxes, and so I wanted all of those rows to be editable and then once the Submit button is pressed all of the rows are updated. However, it seems that with this code only the last of all the rows is being updated.
Is this because it is not possible to do this or is there a different way of doing it? Would I need to put my update query into a WHILE loop to make it work or something?
You can do it with a loop, but the down side is that if the user changes only 1 out of 100 values, the script won’t know that and will issue 99 unnecessary UPDATE statements. You could get more sophisticated by storing the current value in a hidden input field, comparing the text box and the hidden field and only executing the SQL if the values are different.