简体   繁体   中英

Post Array Data from Multiple Selects to Mysql

I have a form-1 which has 4 fields. when the user inputs data in these and hits submit, he is taken to form 2 for further selection of more items from multiple selection box. after selections are complete, he is prompted to update and on updating, all the data has to go to a third form for processing. currently i am passing the single fields data from second form to third form by <input type="hidden" name="abc" value="<?php echo $x[0]?>"> I am getting stuck as to how to retreive all multiple selected items from the array, perform a calculation on them and then post to mysql and then update the user with posted information.

or is there a better way of doing this, pl. guide me. my fields are:-

first page customer id - single selection field date - input segment selection - single selection field

second page items inputs - itemid, quantity,price (these are in one row and user will dynamically add or delete rows based on requirements. i have done this through Javascript)

now after all this, i want to gather all details of customer, segment, items(id,quantities,prices) and then post them to mysql.

If you want to use separate pages you can use either hidden inputs fields or sessions to pass along their selections. With sessions, you'd just store the array of data in $_SESSION and use session_start() on each page to get the session from the previous page. With hidden inputs, you can store them just like you would with session, and when they click POST you will rewrite them into the form. Are you stuck on specific aspect of doing this?

On the final page use either the session or the hidden fields (depending on your chosen method) + the final POST, to query MySQL.

Note: As Zirak mentioned in the comments, you could also do this using a single page. You'd use one of the same methods described above, except it would post to itself rather than to another page. This might be a faster/better way to code the page... If you opt for the single page method just ensure that you make it possible to go back, both through their browsers back button and a link you provide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM