Page 1 of 1

multiple inserts not working

Posted: Wed Jun 09, 2004 6:24 am
by vigour1
Can somebody tell me why is this not inserting multiple values ($tip[], $faza[], $ocj[]) in db. The main thing this should do is when multiple chack boxes are selected there should be multiple rows with values ($tip[], $faza[], $ocj[]) inserted into db.

To be more clear, I select for instance chackbox 1,3,5, in rows where this chackboxes are selected, I then select from menu (second part of the code explain this) values for $tip[], $faza[], and after submit I need 3 ROWS in db table "ocjen_tip" each with selected values.

But all I get is values of tip, faza, ocj for last row in dynamic table from web, The best thing is that this value wasnt even selected with checkbox!!!! :?:

Code: Select all

<?php
global $HTTP_POST_VARS;
if (isset($HTTP_POST_VARS['izabrani']))
{
$izabrani = $HTTP_POST_VARS['izabrani'];

for($i=0; $i<count($izabrani); $i++)
{ 
if ($izabrani == true)
{
$tip[] = $HTTP_POST_VARS['tip_ocjenitelja'];
$faza[] = $HTTP_POST_VARS['faza'];
$ocj[] = $HTTP_POST_VARS['ocjenitelj_id'];

$sql = "INSERT INTO ocjen_tip (faza_id, tip_ocjenitelja, faza, ocjenitelj_id, ustanova_id) VALUES ('".$tNG->recordId."', '".$tip[$i]."', '".$faza[$i]."', '".$ocj[$i]."', '".$tNG->recordId."')";
mysql_select_db($tNG->databasename, $tNG->connection);
mysql_query ($sql, $tNG->connection) or die(mysql_error());

}
}
}
?>
Selecting from dynamic table on web, This is part of the form.

Code: Select all

<td><select name="faza" id="faza">
<?php
do { 
?>
<option value="<?php echo $row_Recordset4['faza']?>"<?php if (!(strcmp($row_Recordset4['faza'], $row_Recordset4['faza_id']))) {echo "SELECTED";} ?>><?php echo $row_Recordset4['faza']?></option>
<?php
} while ($row_Recordset4 = mysql_fetch_assoc($Recordset4));
$rows = mysql_num_rows($Recordset4);
if($rows > 0) {
mysql_data_seek($Recordset4, 0);
$row_Recordset4 = mysql_fetch_assoc($Recordset4);
}
?>
</select></td>
<td><input name="izabranitype="checkbox" id="izabrani" value="<?php echo $row_Recordset1['ocjenitelj_id']; ?>"></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
[edit] feyd - clarified subject, added [php.] tags and moved it to databases.

Posted: Wed Jun 09, 2004 6:40 am
by ckuipers
Try this:

$tip[$i] = $HTTP_POST_VARS['tip_ocjenitelja'];
$faza[$i] = $HTTP_POST_VARS['faza'];
$ocj[$i] = $HTTP_POST_VARS['ocjenitelj_id'];

So define your array elements.

Posted: Wed Jun 09, 2004 7:00 am
by vigour1
I tried that the same thing is happening, just one row is inserted, the last one in table and that row wasnt even selected via checkbox

Any other sugestions?! Thanks