hello am a newbie sad to say but i got a big problem regarding to the auto increment.
i use innoDB for storage but somethinggoes wrong!
i dont know why.
whenever i input new data (such as name add and tel, member ID should increment by one) there is no data stored in my database. pls help me.

Recommended Answers

All 6 Replies

Copy paste your code which is INSERTing the new data.
And check your database is your ID set to autoincrease

Hi, tell me, are you using phpmyadmin ?

If so, go to the structure of the table, have you checked the checkbox for the AUTO INCREMENT ?

If you have not, auto increment will not happen.

Check it and let us know.

Member Avatar

without showing your code we have no idea what's going on. It may be totally unrelated to autoincrement. E.g. you may have misspelt a table or field in your query. Equally dirty input may be responsible.



$sql = "select count 'tb_stugreg'";
$result = mysql_query($sql);
$next_increment = 0;
$qShowStatus = "SHOW TABLE STATUS LIKE 'tb_studreg'";
$qShowStatusResult = mysql_query($qShowStatus) or die(mysql_error());
$row = mysql_fetch_assoc($qShowStatusResult);
$next_increment = $row['autoincrement'];

 $sql = "insert into tb_studreg(id,fname,lname) values($next_increment,'$_POST[fname]','$_POST[lname]')";
 if (!$sql)
     echo "error in saving";
     echo "added";



Now what error you have got?
Please post your codes with code tag.

your problem is not on your php code, it's your table was the problem.
your code to your table sould be like this. i haven't seen you created your table but you should check on your table.

well here is the code to fix that.

CREATE TABLE tb_studreg(
fname varchar(255) NOT NULL,
lname varchar(255),

then to your php code
you dont need this code so remove this code,

$next_increment = $row['autoincrement'];

in your insert code

$sql = "insert into tb_studreg(id,fname,lname) values($next_increment,'$_POST[fname]','$_POST[lname]')";

change this into

$sql = "insert into tb_studreg(fname,lname) values('".$_GET['fname']."','".$_GET['lname']."')";

is this code help you? click solve.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.