multiple inserts not working

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
vigour1
Forum Newbie
Posts: 2
Joined: Wed Jun 09, 2004 6:24 am

multiple inserts not working

Post 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.
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post 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.
vigour1
Forum Newbie
Posts: 2
Joined: Wed Jun 09, 2004 6:24 am

Post 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
Post Reply