EDIT This question has almost duplicated this question since 2010, except that I am not using transactions, so none of the answers make sense.
EDIT I am not asking how to reset the primary key. I ask why the primary key will not automatically increment by consecutive numbers.
I use xmlhttprequest to capture information about you and store it in my Mysql database.
HTML
<input type="text" name="example" onKeyUp="saveData(this)">
JAVASCRIPT
function saveData(a){
var z;
var d=new FormData();
d.append('data',a.value);
if(window.XMLHttpRequest){z=new XMLHttpRequest();}else{z=new ActiveXObject("Microsoft.XMLHTTP");}
z.onreadystatechange=function(){if(z.readyState==4&&z.status==200){if(z.responseText=='false'){alert(z.responseText);}}}
z.open("POST", '/scripts/save_data.php');
z.send(d);
}
PHP
For testing purposes, I hardcode the user ID uid.
<?php
$stmt=$pdo->prepare("INSERT INTO `user_data` (`uid`, `data`) VALUES (:myuid,:mydata) ON DUPLICATE KEY UPDATE `data`=values(`data`)");
$stmt->bindValue('myuid',1,PDO::PARAM_INT);
$stmt->bindParam('mydata',$_POST['data'],PDO::PARAM_STR);
$stmt->execute();
My MySQL table has ...
id, primary INT(10) unsigned auto-increment
uid, INT(10) unsigned
data, VARCHAR(24)
, , , id , (1, 2, 3 ..). (1, 20 ..), , , . - ? ?