Question: I have a form with over 100 dynamically named fields, that post to a php file, I want to take all the fields that are posted to the php file which is currently:

```
Array ( [option_page] => plugin_options 
[action] => update 
[_wpnonce] => a51bfc281a 
[_wp_http_referer] =>/wp-admin/options-general.php page=plug.php 
[13939069] => 
[2171] => 
[3600645] =>
[2168] => 
[13937024] => 
[submit] => Save Changes 
[__qca] => P0-1887521465-1334258158937 
[s_vi] => )

```

From this I want to insert the data into a mysql table in the format:

```
id      | option_name     | value
--------------------------------------------
autonum | post data key   | post data value

```

But the issue is I am only intrested in the post data value after: [\_wp\_http\_referer]
but before [submit] so these can be used as reference points.

The part I am stuggling with is:

* how would I get only that part of the post data dynamically?
* How would I get the required array keys and insert it into the
table dynamically?

Many thanks!

Answer: 
You mat try this

```
$start = array_search("_wp_http_referer",array_keys($_POST))+1;
$end = array_search("submit",array_keys($_POST))-1;
$newArr=array_slice($_POST, $start, $end);
foreach($newArr as $k=>$v)
{
    // $k is the key name and $v is the value of that key
    //echo $k."=".$v."<br />";  
    $val=mysql_real_escape_string($v);
    $sql="INSERT INTO table_name VALUES (null, ".$k.", ".$val.")";
    mysql_query($sql);
}

```
```
$counter = 0;

foreach($_POST as $key=>$value)
{

if($key == "_wp_http_referer")
{
$counter = 1;
}

if($counter == "1")
{
if($key != "submit")
{
mysql_query("INSERT INTO table_name(id, option_name, value) VALUES ('','".mysql_real_escape_string($key)."','".mysql_real_escape_string($value)."')");
}
}

}

```