How to iterate form-fields on a page and send them to database? [modified]
-
I am trying to submit a form on my page. It's proving to be a very difficult and frustrating task. The problem is that there is no way of telling how many 'fields' will need to be submitted. The user might add 50 products to the cart, and make 30 changes to the quantities, or they might add 600 products to the cart and make 599 changes to the quantities (you never know), and with this website, the client is expecting high volume of sales so I need to be prepared for cases such as that. I have a Table (a script that I bought) which has its own form tag for the data inside the table, however it uses GET not POST. And I am using:
foreach($_GET['items'] as $p=>$q)
{
// Update in database. This sql query has been tested, so I know it works, which means that the problem lies within the foreach loop, since it only stopped working when I added the foreach loop to update all form fields.
}But I dont know how to do this. I have tried hundreds of variations of the above snip and NOTHING has worked for me. I have searched all ovver php.net, google and am out of ideas, and would greatly appreciate anyone's advice or help. How can I update ALL form fields to the database? Thanks Edit: The result of
print_r($_GET);
is: Array ( [ct_items_per_page] => 10 [ct_sort] => t_t_t_t [ct_page] => 1 [ct_search] => [ct_items_per_page_change] => all [ct_multiple_search] => Array ( [0] => [1] => [2] => [3] => ) [product] => M5 x 1 MTR Allthread (Grade 304 Unit Price) [items] => Array ( [1] => 45 ) ) Edit: What else would work in my situation? Does anyone have any links/tutorials/articles? I cannot find anything anywhere. Are there other ways to submit all fields to a database?
modified on Monday, March 28, 2011 1:18 AM
-
I am trying to submit a form on my page. It's proving to be a very difficult and frustrating task. The problem is that there is no way of telling how many 'fields' will need to be submitted. The user might add 50 products to the cart, and make 30 changes to the quantities, or they might add 600 products to the cart and make 599 changes to the quantities (you never know), and with this website, the client is expecting high volume of sales so I need to be prepared for cases such as that. I have a Table (a script that I bought) which has its own form tag for the data inside the table, however it uses GET not POST. And I am using:
foreach($_GET['items'] as $p=>$q)
{
// Update in database. This sql query has been tested, so I know it works, which means that the problem lies within the foreach loop, since it only stopped working when I added the foreach loop to update all form fields.
}But I dont know how to do this. I have tried hundreds of variations of the above snip and NOTHING has worked for me. I have searched all ovver php.net, google and am out of ideas, and would greatly appreciate anyone's advice or help. How can I update ALL form fields to the database? Thanks Edit: The result of
print_r($_GET);
is: Array ( [ct_items_per_page] => 10 [ct_sort] => t_t_t_t [ct_page] => 1 [ct_search] => [ct_items_per_page_change] => all [ct_multiple_search] => Array ( [0] => [1] => [2] => [3] => ) [product] => M5 x 1 MTR Allthread (Grade 304 Unit Price) [items] => Array ( [1] => 45 ) ) Edit: What else would work in my situation? Does anyone have any links/tutorials/articles? I cannot find anything anywhere. Are there other ways to submit all fields to a database?
modified on Monday, March 28, 2011 1:18 AM