Simple PHP Insert Page has Random Failure with MySQL
| From: | dealtek@gmail.com | Date: | Fri, 18 Mar 2016 15:10:22 +0000 |
| Subject: | Simple PHP Insert Page has Random Failure with MySQL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-325477@lists.php.net to get a copy of this message | ||
Hi all,
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?
---
require_once('inc/db/class.db.php');
/* this for testing */
$_POST['id'] = 1;
$_POST['first'] = 'test';
$_POST['last'] = 'test';
$_POST['cellphone'] = '1112223333';
$_POST['email'] = 'test@test.com';
$_POST['city'] = 'test';
$_POST['zip'] = '11111';
$insert = array(
"id"=>$_POST['id'],
"first"=>$_POST['first'],
"last"=>$_POST['last'],
"cellphone"=>$_POST['cellphone'],
"email"=>$_POST['email'],
"city"=>$_POST['city']
"zip"=>$_POST['zip']
);
$db->insert("contacts", $insert);
$newpbid = $db->lastInsertId();
echo $newpbid;
-----
--
Thanks,
Dave - DealTek
dealtek@gmail.com
[db-16]