[PHP] Simple PHP Insert Page has Random Failure with MySQL
I was working on a very simple php page to insert a new record into a mysql 'contacts' table. For testing, when I would refresh the page it would insert the new record.
This worked fine - MOST of the time. Then, oddly randomly it would stop inserting records. I would click refresh several times and no new records got created. Then I might quit the browser or wait a while etc. then reload and it would work again for a while then stop again...
one clue is the table looked like this with missing serial ID's:
Rec 1 - fields...
Rec 2 - fields...
Rec 3 - fields...
Rec 7 - fields...
Rec 8 - fields...
Rec 12 - fields...
Rec 13 - fields...
Rec 14 - fields...
so it seems the page went to mysql and tried to insert a record but failed for some reason. Since it was static test data - it was all the same so it seems that can be ruled out.
Also this is a very fast server with local mysql - so that should not be an issue.
Any idea why it might be randomly failing to insert records?
/* this for testing */
$_POST['id'] = 1;
$_POST['first'] = 'test';
$_POST['last'] = 'test';
$_POST['cellphone'] = '1112223333';
$_POST['email'] = 'test@xxxxxxxx';
$_POST['city'] = 'test';
$_POST['zip'] = '11111';
$insert = array(
$newpbid = $db->lastInsertId();
Dave - DealTek