You should definitely use automatic fields in the database and get them to be updated automatically...
Your design could allow that two people would access the database at the same time and then try to insert the same data. And you don't have any way to avoid that except the one described before...
Use primary/secondary keys, and autonumeric fields in your database; in that way you will avoid this kind of situations.
If you have problems doing that you should tell us the kind of database you are using and therefore we would be ready to help...
Good luck.
* IMPROVEMENT 1:
The idea is that you should not introduce the key manually in order to avoid duplicate values.
You should check if the data introduced is already there and if it is not, then you should INSERT it normally but without the senderId.
The MySQL database (if using AUTO-INCREMENT) will make that for you.
Take a look at
this link[
^] where you will find some extra details about using AUTO-INCREMENT and a sample of the scenario I'm talking about.
* IMPROVEMENT 2:
Take a look at
this link[
^].
Hope this helps.