HTML Help Forum HTML Help
Please Search for the answer to your question before asking it! Thanks.
 

MYSQL and Insert Records Issue on Multipage Form
Post a Reply to this Topic Ask a New Question
Click here to go to the original topic
       HTML Help Forum -> PHP
View previous topic :: View next topic  
Author Message
Sydney34



Joined: 31 Jan 2009
Posts: 3

Posted: Wed Mar 04, 2009 1:28 am     MYSQL and Insert Records Issue on Multipage Form  

Hi everyone,

Just need a little help on a site I am working on..
I have to create a 10 page form and insert info into a mysql db.. about 50 fields.. I was going to insert info after each page.. ie after page 1, page 2, page 3 etc.. however hit a problem.. when I do this all the records do not appear in the same db entry.. rather the info from page 1 is inserted in the db as say db entry 1, page 2 info goes in as seperate db entry.. and page 3 info goes in as yet another db entry...

I need them all to be in the same db entry.

I have set up the mysql db with 1 table and put the 50 fields/colums in that..

Can someone tell me how I can get the info from pages 2 to 10 to insert in the same db entry as page 1??

Thanks again everyone.

Cheers
rsleventhal



Joined: 19 Mar 2008
Posts: 26

Posted: Wed Mar 18, 2009 5:40 am     Re: MYSQL and Insert Records Issue on Multipage Form  

Sydney34 wrote: Hi everyone,

Just need a little help on a site I am working on..
I have to create a 10 page form and insert info into a mysql db.. about 50 fields.. I was going to insert info after each page.. ie after page 1, page 2, page 3 etc.. however hit a problem.. when I do this all the records do not appear in the same db entry.. rather the info from page 1 is inserted in the db as say db entry 1, page 2 info goes in as seperate db entry.. and page 3 info goes in as yet another db entry...

I need them all to be in the same db entry.

I have set up the mysql db with 1 table and put the 50 fields/colums in that..

Can someone tell me how I can get the info from pages 2 to 10 to insert in the same db entry as page 1??

Thanks again everyone.

Cheers
Hi Sydney,

The issue you're having is that only the first db insert should be done with 'insert'. The rest should be done with 'update'.

Example: If you have a 9 field database table and you're doing 3 fields per page, after the first page ensure you have a unique value or create an auto_increment field in your table so you can use it as a reference. Then execute:

Code: $page1 = mysql_query("insert into `table_name` (`field1`, `field2` `field3`) values ('form_field1', 'form_field2', 'form_field3') or die ('Insert not executed');

Subsequent submit buttons should execute:
Code: $page2 = mysql_query("update `table_name` set `field4` = 'form_field4', `field5` = 'form_field5' where `field1` = 'some_value');

By using 'update' instead of 'insert', you're adding or changing values to an existing record.

I hope his points you in the right direction.

Regards,
-Ray
Sydney34



Joined: 31 Jan 2009
Posts: 3

Posted: Wed Mar 18, 2009 2:06 pm      

Yeah right that makes sense... Thanks alot for the help.. will try to put it all together tonight and see if I can get it to work...

Cheers
bhende19



Joined: 02 Jun 2009
Posts: 2

Posted: Tue Jun 02, 2009 6:37 am     Another way - use $_SESSION variables  

Another way is to store the values from each page in the $_SESSION array and then insert into the database all in one go.
 
 
DARFUR
HOSTING / DESIGN
MAKE MONEY

       HTML Help Forum -> PHP
Page 1 of 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.19 © 2001, 2002 phpBB Group