Page 1 of 1

PHP with MySQL Question

Posted: Sun Feb 15, 2009 10:02 pm
by FlightFanatic
Hello, I am making a PHP website, and I have it input information into a MySQL Database. I have one question about this though, how can I, if possible, while the information is being put into the MySQL Database, it looks at the first column, and there is a ID column, which changes for every new entry, I drew up some pictures to help explain what I am trying to describe, any help is greatly appreciated! Thanks a bunch!

| This is the normal php page, which has input boxes
|
\/

Image

This is in the MySQL Database, and see the ID 1? which is in the ID column? |when there is a new entry, the ID would be +1, which would be 2, and the third one down would be 3, basically add 1 to the last ID in the table... So in other words, it will find look at the last column, and the last ID number, and add 1 to it, and insert the next number on the next line down!
\/

Image

-FlightFanatic

Re: PHP with MySQL Question

Posted: Sun Feb 15, 2009 11:11 pm
by susrisha
while creating the table, you can add an attribute to the column 'id' as auto_increment.
Here is the script you might have to use to create the mysql table.

Code: Select all

 
CREATE TABLE tbl_contact (ID int not null auto_increment, Name varchar(30), Address varchar(100), Phone varchar(25), primary key(ID));
 
This way you need not enter the id while inserting. Mysql automatically updates the id and enters the number.

You can also set the starting number of id to any number( if not specified, it will start from 1.)

Re: PHP with MySQL Question

Posted: Tue Feb 17, 2009 8:06 am
by FlightFanatic
Ok, thank you for the help! I got it to work! :bow:

-FlightFanatic