Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem INSERTING recordID

Status
Not open for further replies.

alphacooler

Programmer
Aug 29, 2005
73
US
I am an ultraNOOB...keep this in mind (i.e. speak to me like a child).

I have two tables
TABLE1 columns: ID, name, address, etc...
TABLE2 columns: ID, comments

I have a search page that brings up records.
Each record is a link to a "details page" and uses the URL to hold the Unique record ID
The details page has a "add comments" link which takes the user to another page. Call this page "update.php" In the url of update.php there is still ?recordID=4 (i.e. it still has the correct unique ID).

On update.php I have a simple form that has one comments field and a submit buton. My problem is trying to figure out how to INSERT the comments to TABLE2. Obviously the ID column in TABLE2 is not a unique primary key (I want to allow posting of multiple comments for the same ID).

I tried simply using a Hidden Field in the form for the ID, but that would only submit empty strings to my db for some reason.

Does anyone know of the best way to insert the ID from the URL into TABLE 2 along with comments?
 
The unique primary key in TABLE2 is not used to record the recordid from TABLE1. If it is an auto_increment primary key, it is used to store a MySQL-generated recordid. You will then have another column which will store the recordid from TABLE1

So, TABLE2 will look like:

CREATE TABLE TABLE2
(
ID int unsigned auto_increment primary key,
t1_ID int unsigned,
comments varchar(255),
.
.
.
)




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
So sorry, I forgot to note that I have 1 more column in TABLE2 called PRIMARYKEY and this is the primary key. So in TABLE2 column "ID" is not the primary key. I believe it is setup as a "key" though.

So I assume using a hidden field in my form to INSERT the TABLE1 ID into TABLE2 column "ID" is ok? It is still just inserting "0" the default value.

Thanks.
 
You can use whatever method is appropriate. Hidden fields are fine.

If you're not getting a value from the hidden field, verify you're setting the field's value correctly when the form is generateed and verify you're referencing the variable correctly in the destination script.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top