select and insert from form to database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
erinther
Forum Newbie
Posts: 19
Joined: Sun Dec 11, 2005 2:07 pm

select and insert from form to database

Post by erinther »

Here is the problem:

1-I've a table in my database named: mt_entry
2-This table has these fields: entry_id, entry_category,entry_text,title,date and so on...
3-I know to sending information via a form to this database, I can use a insert query.
But each time a user visits the form page to send a new entry to database, I need that a php code gets the last entry's id and adds 1 to it and put this id inot a hidden input inside the form,named "entry_id".
My question is that: how should I write such a code segment? and how can I be sure that every time a user sends an entry to database it will get a unigue id (the last entry's id + 1)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not set entry_id as the primary key and enable auto_increment on it?
erinther
Forum Newbie
Posts: 19
Joined: Sun Dec 11, 2005 2:07 pm

no knowledge of php

Post by erinther »

simply because I have no knowledge of php and sql queries. When I said I know how to insert details in database, because I've some written php code examples. Can you please write me the required code?Thanks in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: no knowledge of php

Post by feyd »

erinther wrote:Can you please write me the required code?
No, I'm not here to do the work for you. I can direct you in the right direction.

http://dev.mysql.com/doc/refman/4.1/en/alter-table.html
erinther
Forum Newbie
Posts: 19
Joined: Sun Dec 11, 2005 2:07 pm

Thanks

Post by erinther »

Thanks for the link.
Post Reply