473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

need help understanding IDs

I have a table where users can insert info from a form. I want to have an ID # that distinguishes the posts.

Here is a simplified version of my table:

Email, Subject, Description, ID

When the user fills the info out i want to have them fill out the first three fields and I want the ID to automatically become 1 number larger than the id from the last entry into the table.

I know this has something to do with AUTO INCREMENT though im not sure exactly how this works.


Also:
$query = "INSERT INTO ads VALUES('$email', '$subject', '$description','ID')";
when i execute this command do i need / want the ID or do i leave this out?
Apr 14 '07 #1
1 948
Motoma
3,237 Expert 2GB
You will want to take up a couple of MySQL tutorials from the many listed on Google. This will (should) teach you about database integrity, normalization, and indexes.

To get to your answer, you will need to change your table so that your ID column is your PRIMARY KEY, NOT NULL, and AUTO_INCREMENT. Then, when you do your INSERTs, you will not have to assign a value for your ID, only the Columns that are user data.

The second way to do this is by using a message router. This consists of having a separate table which contains the next ID to assign. Any time you want to do an insert, you lock the row for your table, grab the number, increment the number, and update the table. Then you assign the number to your INSERT statement.

Hope this helps,
Motoma

I have a table where users can insert info from a form. I want to have an ID # that distinguishes the posts.

Here is a simplified version of my table:

Email, Subject, Description, ID

When the user fills the info out i want to have them fill out the first three fields and I want the ID to automatically become 1 number larger than the id from the last entry into the table.

I know this has something to do with AUTO INCREMENT though im not sure exactly how this works.


Also:
$query = "INSERT INTO ads VALUES('$email', '$subject', '$description','ID')";
when i execute this command do i need / want the ID or do i leave this out?
Apr 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
Hey guys, need some help understanding some things that maybe someone can explain or clarify it a little better then a text book. Here is my understanding so far: Class - basically a shell for...
3
by: Newbie | last post by:
I am extremely new to the working of XML. Our client wants us to access their Website. They also want us to retrieve XML (files?) from their site. We will then somehow import it into our SQL...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
1
by: Learner | last post by:
Hi there, I have designed a three tier arichitecture(presentation, business and datalayer). I have used Shared keyword in all my DL methods inorder to make them available in my BL. I have...
7
by: Buck Rogers | last post by:
Hi all! Newbie here. Below is an example from Teach Yourself C in 21 Days. My apologies if it is a bit long. What I don't understand is how the "get_data" function can call the...
8
by: BJ | last post by:
Problem: How can I code up a client side process to detect if the network is available? Synopsis: I am writing ASP.NET input forms for a Panasonic Tuff book. The users will be walking around...
0
by: Global Infotech Corporation | last post by:
Hi We have the following two positions open at one of our Client's site in the Silicon Valley, CA area. Our client, apart from being a pioneer in desktop publishing software provider, also makes...
1
by: SteveM | last post by:
I am writing a ToolUsage tracker which we will be accessing from each of our custom written tools. It will basically capture various pieces of information about the user, and the application they...
6
by: Steven W. Orr | last post by:
Given the following code: (I hope it's as simple as possible) :-) #! /usr/bin/python import new class BASE: def __init__( self ): print 'Hello from BASE init' def m1( self ): print 'M1 Base:...
0
by: J de Boyne Pollard | last post by:
hNow the next step is to write malloc and free, for kernel hheap management. I am keeping my kernel heap at h0XD0000000. My understanding is that malloc calls sbrk hto allocate more memory to the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.