PHP with MySQL Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FlightFanatic
Forum Newbie
Posts: 11
Joined: Sun Feb 15, 2009 9:54 pm

PHP with MySQL Question

Post 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
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: PHP with MySQL Question

Post 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.)
FlightFanatic
Forum Newbie
Posts: 11
Joined: Sun Feb 15, 2009 9:54 pm

Re: PHP with MySQL Question

Post by FlightFanatic »

Ok, thank you for the help! I got it to work! :bow:

-FlightFanatic
Post Reply