Dear sir:
it's obvious you are doing something wrong.
- You need an autoincrement PK in invoice table.
- You must generate an unique record from invoice mysql_insert() which return you a new ID.
- Using this ID for all detail record you wont problems:
ER:
INVOICES:
Id(PK-Auto), Number(UNIQ), Date, IdClient, ....
INVOICEDETAILS:
Id(PK)-Auto, IdInvoice, IdProduct, Price, Qty, ...
Send me all details and I will check for you.!!
regards