First of all, things like “the results are wrong” are not helpful at all at locating the error. We don’t know what the results are, and what they should be. You should try to be more clear in describing your problems.
Second, take a look at that code, especially at what you’re doing inside the loop. At each iteration, you give the variables a new value, based on that iteration only. But the query is executed only at the end of the loop. So you only insert the data from the latest iteration.
In your update query you don’t have any WHERE conditions, so all rows will be updated?
Isn’t that what you want? Then what do you want? You have to specify what rows you want to update (just like you do when you SELECT rows).
When you’re starting out, sometime it is better to do it the long way. After using regular expressions in over ten years, I’m still having problem of condensing the code to a minimum. I only can see how the match is done by expanding each segment.
I would do what guido suggests, get the output from the query and compare that to what you are expecting. So just echo $sqlupdate1 and you might see the reason why.