Prince Munene
Prince Munene

Reputation: 21

mysql insert auto increments but does not insert row

I need guidance on something that is confusing me. I have a mysql insert query that works like 99% of the time but in some few cases, the auto increment field updates but the row is not inserted. The query is as below:

$result = mysql_query("insert into receipts 
  values('','".$rcptno."','".$cid."','".$names."','".$stream."','".$pname."',
  '".$fintot."','cr','".date('Y/m/d')."','".date('Ymd')."','1','".$username."','".
  $sess."','".$refno."','".$prevbal."','".$newbal."')");

When I try inserting the same data again, it inserts perfectly. I would just like to know what might be causing this issue.

Thanks in advance.

Upvotes: 2

Views: 1627

Answers (1)

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18825

The id is always incremented. But in case the insertion fails because of some trigger or the transaction is rolled back, the autoincremented value is not reused.

Upvotes: 1

Related Questions