Home > Archive > PHP SQL > April 2004 > insert multiple rows in one table
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
insert multiple rows in one table
|
|
| Rayne 2004-04-07, 10:31 pm |
| I have this in my form that gets all the values from one table:
<input type="hidden" name="ws_id[]" value="$ws_id">
<input type="hidden" name="record_id[]" value="$record_id">
Then I have this to insert all the record_id found into a different table:
//start trigger Trigger1
function KT_TriggerAFTER_Trigger1(&$tNG) {
global $HTTP_POST_VARS;
$ws_id = $_POST['ws_id'];
$record_id = $_POST['record_id'];
$num = COUNT($record_id);
$sq1 = 'INSERT events_registrants (record_id, ws_id) VALUES ('
for ($i = 0; $i < $num; $i++) {
$sq1 .= "('" . $record_id[$i] . "', '" . $ws_id[$i] . "')";
if (($num - $i) > 1) {
$sq1 .= ', ';
}
}
mysql_query ($sq1);
@mysql_select_db($tNG->databasename, $tNG->connection);
@mysql_query($sql1, $tNG->connection);
if (mysql_errno()>0){
$tNG->setError(-1, "Cannot insert the information into the
events_workshopReg for the following reason:
" . mysql_error());
}
}
}
//end trigger Trigger1
But I get a parse error on this line: $num = COUNT($record_id);
Can someone tell me where I am going wrong?
Thanks.
| |
| Leroy 'Perfect' Gordon 2004-04-08, 1:32 am |
| Try putting a semicolon after
$sq1 = 'INSERT events_registrants (record_id, ws_id) VALUES ('
"Rayne" <rayne@hal-pc.org> wrote in message
news:4074a501$0$1341$a726171b@news.hal-pc.org...
> I have this in my form that gets all the values from one table:
> <input type="hidden" name="ws_id[]" value="$ws_id">
> <input type="hidden" name="record_id[]" value="$record_id">
>
> Then I have this to insert all the record_id found into a different table:
>
> //start trigger Trigger1
> function KT_TriggerAFTER_Trigger1(&$tNG) {
> global $HTTP_POST_VARS;
>
> $ws_id = $_POST['ws_id'];
> $record_id = $_POST['record_id'];
> $num = COUNT($record_id);
> $sq1 = 'INSERT events_registrants (record_id, ws_id) VALUES ('
> for ($i = 0; $i < $num; $i++) {
> $sq1 .= "('" . $record_id[$i] . "', '" . $ws_id[$i] . "')";
> if (($num - $i) > 1) {
> $sq1 .= ', ';
> }
> }
>
> mysql_query ($sq1);
>
> @mysql_select_db($tNG->databasename, $tNG->connection);
>
> @mysql_query($sql1, $tNG->connection);
>
> if (mysql_errno()>0){
>
> $tNG->setError(-1, "Cannot insert the information into the
> events_workshopReg for the following reason:
> " . mysql_error());
>
> }
> }
> }
> //end trigger Trigger1
>
> But I get a parse error on this line: $num = COUNT($record_id);
>
> Can someone tell me where I am going wrong?
> Thanks.
>
>
| |
|
| Thanks for the reply. That solved the parse error, but the code doesn't put
the values in the table. How do you write multiple rows in one table?
"Leroy 'Perfect' Gordon" <webmaster@music24seven.com> wrote in message
news:h_4dc.7238$WX.5045@nwrdny01.gnilink.net...
> Try putting a semicolon after
> $sq1 = 'INSERT events_registrants (record_id, ws_id) VALUES ('
>
> "Rayne" <rayne@hal-pc.org> wrote in message
> news:4074a501$0$1341$a726171b@news.hal-pc.org...
table:[color=darkred]
>
>
|
|
|
|
|