Thanks to all the suggestions. However, after taking a closer look at the code next day I think, I figured out the problem (well, the script is working now). I have included my "INSERT" statement within "SELECT" while loop. It seems like when running "while" loop with select, MySQL locked the table and this was the reason why I could not write anything to it. I simply took "INSERT" out of the loop and now it's O.K.
Thanks again.