I think I got it figured out. I'm not a PHP programmer (or any type of programmer), but after much research I used printf and sprintf and it's working fine. But I still need help with (from above):
"As far as the DetailProductId column, it's picking up the autoincremented ID field in my products db. I want to change it to pick it up from my 'MessageNumber' column, but I still can't find where to change this. "