Saving Form Data for Later?

Permalink
I can't seem to figure out how to save form data in an array and store it for later in the database. I can get the current data, but then as soon as a new request is generated that is lost. Thinking its something simple, but can't find it by searching adodb or the forums. Thanks!

12345j
 
jordanlev replied on at Permalink Reply
jordanlev
What's the context here? Assuming it's a block, you would need to create a table for the block (via the db.xml file) and save it to that table. There's tons of code in many of the built-in blocks that do this, basically something like this:
$db = Loader::db();
$sql = "INSERT INTO your_table_name (fieldname1, fieldname2) VALUES (?, ?)";
$vals = array($data1, $data2); //<--or this could just be the array you have created from the form's $_POST data, just make sure the elements are in the same order you've put "fieldname1, fieldname2" etc. in the sql statement above
$db->query($sql, $vals);
12345j replied on at Permalink Reply
12345j
sorry, I guess I was a little unclear. It is in a block. Yes, I can do something like that, but then the data gets overwritten each time. I want to be able to get the form data from each of the submissions in an array, so that I can step through all the values. Thanks!
jordanlev replied on at Permalink Reply
jordanlev
You want to use an INSERT statement in your SQL, not an UPDATE -- then nothing gets overwritten -- only new records added.

Note that you'll want to create another table (other than the block's primary table) for these, since there will hopefully be more than 1 form submission per block.