Nearly completed table inserting for sample

So far it writes to the table fine, but I'm still figuring out two
probems: one is that my query for exsisting rows with same informaton
doesn't produce any results. The other problem is that I'm not capturing
the id when i create a new row, so the final table insert fails.