Page 1 of 1

problem inserting data into table

Posted: Sat Oct 05, 2013 6:06 pm
by hybris
Hi,
How do I insert data to a table where the third column is autoincreaseing? Like
*age*nr*id*name*surname * time
Where id is autoincreasing.

Code: Select all

IF($stmt=$mysqli->prepare("INSERT INTO user (age, nr, name, surname, time) VALUES (?, ?, ?, ?, ?)" )) {
$stmt->bind_param('iisss' $age, $nr, $name, $lname, $time);
$stmt->execute();
}
If I just set age and nr the db is inserting age nr and id but as soon as I try to insert after if it doesn't work? What am I missing?
Thanks

Re: problem inserting data into table

Posted: Tue Oct 15, 2013 4:10 am
by social_experiment
from what i've experienced you just leave the column out of the query and it auto-increases as it should

Re: problem inserting data into table

Posted: Sat Oct 19, 2013 6:22 am
by priyankagound
Try out with the below example:
suppose below is table created:
CREATE TABLE Persons
(
ID int NOT NULL AUTO_INCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
PRIMARY KEY (ID)
)

so the insert qury will be as foolows for it:
INSERT INTO Persons (FirstName,LastName)
VALUES ('Lars','Monsen')

By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.

To let the AUTO_INCREMENT sequence start with another value, use the following SQL statement:

ALTER TABLE Persons AUTO_INCREMENT=100

Hope this helps.