Page 1 of 1

select and insert from form to database

Posted: Wed Mar 15, 2006 2:11 pm
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)?

Posted: Wed Mar 15, 2006 2:16 pm
by feyd
why not set entry_id as the primary key and enable auto_increment on it?

no knowledge of php

Posted: Wed Mar 15, 2006 2:32 pm
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

Re: no knowledge of php

Posted: Wed Mar 15, 2006 2:40 pm
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

Thanks

Posted: Wed Mar 15, 2006 2:43 pm
by erinther
Thanks for the link.