0

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.

6
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by decade
0

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

0

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.

0

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.

0
<?php
include("connect.php");


mysql_select_db("db_library"); 

$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";
 }
 else
 {
     echo "added";
 }


?>
</body>

</html>

Edited by pyTony: fixed formatting

0

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(
id int NOT NULL AUTO_INCREMENT,
fname varchar(255) NOT NULL,
lname varchar(255),
PRIMARY KEY (id)
)

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.

Edited by decade: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.