quick array question ...

I’m pulling values from an array to insert into my database. What I have currently is working fine, however I want to add a field to the form and have it added as well. I can’t figure out how to add the new field to my insert logic.

The following code pulls the data from the form and then looks to see which item in the form list has been selected.

[php]
$post = JRequest::get(“post”);
$selected = array()
foreach ($post as $key => $value) {
if (substr($key, 0, 6) == “spare_”) {
if ($value == “1”)
$selected[] = substr($key, 6);
}
}
[/php]

And then for each one selected, it is added to the database using the following code:
[php]
foreach ($selected as $league) {
$query = “insert into #__subbing(userid, leagueid) values(” .
“’” . $user->id . “’, '” . $league . “’)”;
$db->setQuery($query);
$db->query();

            }

[/php]

I’ve added a field to the form called “prefered_position1” which is a select form item.
Basically, I just want it written to the database with the other values shown on the insert above. To do so, I need to add it to the array above first I think??? This is what I’m not sure of how to do.

Thanks!

I’m not familiar with this API but the first bit of code is only searching for keys that begin with “spare_” and have a value of “1”. So I don’t believe this is where you would add a custom field.

You should probably ask on the Joomla forum

Sponsor our Newsletter | Privacy Policy | Terms of Service