# Database Discussions > MySQL >  Auto Incremet Query is not working

## Shahnawaz

Hey dears, I have a problem with my auto increment feature of mysql. I have set my user_id field as a primary key and also auto increment . But it is not working. What are possible errors. Remeber one thing i am doing it with php. Please help me! :Confused:

----------


## cnnx

There could be a number of causes for this error if you are using PHP, but I would start at the SQL level to make sure you know what your increment value is set to.  You can do this with the following command:

ALTER TABLE <TABLE NAME HERE> AUTO_INCREMENT = 1;

This will set the value to 1 and you can work from there on, so you know what to expect in your php variable.  Are you using a MySQL function to retrieve the result set of you sql query and then assign the increment result to a php $variable?

Regards,

http://www.freemysql.org

----------


## kred

Shahnawaz,
When you create table, you sould have something like this:
CREATE TABLE mytable (
     id MEDIUMINT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
) ENGINE=MyISAM;

----------

