Insert multiple rows with posted data

by Daniel Jensen   Last Updated July 03, 2018 10:10 AM

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:

$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 .... "

Tags : php mysql


Related Questions


Display a Value from a Specific DB Field

Updated April 30, 2016 08:04 AM


Delete users from Joomla V2.5

Updated November 08, 2016 08:04 AM

MySQL Query to show images

Updated May 10, 2017 11:10 AM