I want to insert a row in my db-table with inputs from users. The form the users fill out is made with a foreach-loop:
foreach ($results as $row) {
echo '<div class="vm_kampe"><input type="hidden" name="kid['.$row->id.'" value="'.$row->id.'">'.$row->hhold.' - '.$row->uhold.'</div>
<div class="vm_result"><input type="text" class="vm_resultat" name="resu['.$row->id.'" placeholder="?-?" value="'.$row->resu.'"></div>
<div class="vm_1x2"><input type="text" class="vm_1x2" name="bet['.$row->id.'" placeholder="1X2" value="'.$row->bet.'"></div>';
};
On the receiving-end, I tried this, but doesn't work:
$jinput = JFactory::getApplication()->input;
$id = $jinput->get('kid');
$resu = $jinput->getString('resu');
$bet = $jinput->getString('bet');
$uid = $user->id;
$liga = 'bs';
foreach ($id as $key => $k) {
$columns = array('id', 'uid', 'liga', 'resu', 'bet');
$values = array($db->quote($k), $db->quote($uid), $db->quote($liga), $db->quote($resu[$key]), $db->quote($bet[$key]));
$query->insert($db->quoteName('tip3_kuponer'))->columns($columns)->values(implode(',', $values));
$db->setQuery($query);
$db->execute();
};
It just say something about:
invalid argument in foreach....
$jinput->get('kid');
will no doubt be returning a single string, not an array. You cannot loop through a string.$data = JFactory::getApplication()->input->post->getArray();
Then loop through the$data
array