Here is the error?

Hi everyone again,

Insert multi row

[php]$query = ‘INSERT INTO table_name (id, receiver_id, receiver_amount) VALUES (5, (’ .implode(’), (’, $_REQUEST[‘receiver_id’]). .implode(’)’, ‘(’, $_REQUEST[‘receiver_amount’]) . ‘))’;
$result = mysql_query($query)
or die(‘Could not execute INSERT query’);[/php]

Sample:

  id         receiver_id          amount
   5             3                   12
   5             1                    5
   5             5                    8

Thanks

using implode isn’t the way to do it, not if you’re just putting a single number in the row.
[php]
$query = ‘INSERT INTO table_name (id, receiver_id, receiver_amount) VALUES (5, $_POST[‘receiver_id’], $_POST[‘receiver_amount’])’;
$result = mysql_query($query) or die(mysql_error());[/php]

I don’t know how this info is being gotten, so we really can’t tell you how to do multiple inserts, other than you’ll probably need a for loop.

Thanks for the reply,

To me need multi-line

$id=5;

$receiver_id=implode(", ", $_REQUEST[‘receiver_id’]);
Output: 2, 5, 7

$receiver_amount=implode(", ", $_REQUEST[‘receiver_amount’]);
Output: 5, 8, 17

Table

  id         receiver_id          amount
   5             2                   5
   5             5                    8
   5             7                    17


id, Not AUTO_INCREMENT

Thanks

Right, but the table you gave doesn’t support that, you’re showing us just 1 number in each column. If you’re wanting to store mutiples in one field, then you need to change the data type to text. Then you can do
[php]
$query = “INSERT INTO table_name (id, receiver_id, receiver_amount) VALUES (5, '$receiver_id, ‘$receiver_amount’)”;
$result = mysql_query($query) or die(mysql_error());[/php]

If $_REQUEST[‘receiver_id’] and $_REQUEST[‘receiver_amount’] are always the same size and same order you can do something like this:

[php]
$id = 5;
$receiver_id = array(2, 5, 7);
$receiver_amount = array(5, 8, 17);
$values = array();

for($i = 0; $i < count($receiver_id); $i++) {
$values[] = “({$id}, {$receiver_id[$i]}, {$receiver_amount[$i]})”;
}
echo “INSERT INTO table_name (id, receiver_id, receiver_amount) VALUES " . implode(”, ", $values);
[/php]

It will output

INSERT INTO table_name (`id`, `receiver_id`, `receiver_amount`) VALUES (5, 2, 5), (5, 5, 8), (5, 7, 17)

@m@tt, Php You a professor
I do not know how to thank you
Thank you very very very

The code works no problem,
but,

name=“receiver_id[]”
name=“receiver_amount[]”;

How do I get into array()?

$_REQUEST[‘receiver_id’] and $_REQUEST[‘receiver_amount’]

$receiver_id = array(2, 5, 7);
$receiver_amount = array(5, 8, 17);

Thank you again

for($i=0; $i<count($_POST[‘receiver_id’]); $i++) {
$receiver_id[] = $_POST[‘receiver_id’][$i];
$receiver_amt[] = $_POST[‘receiver_amount’][$i];
}

Thank you very much

Best Regards

Hello again,

I have a smal problem,

It is not working without selecting first row.

1st row is selected : running
1st and 2nd rows are selected : running
1st , 2nd and 3rd rows are selected : running
1st, 2nd, 3rd and 4th rows are selected : running

1st row is not selected but the other rows are selected : not running

http://awesomescreenshot.com/0c8m4to53
NOTE: The rows are not standart. They may be 1 or more.

Thanks

I’m not sure if I understand the problem. It sounds like you should remove the empty value from the select box so there must be an option selected?

Hello again,

1. row selected no problem at. working

1. row not selected, there is a problem . does not work
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘)’ at line 1

step7.php code:
[php]
<?php
while ($row = mysql_fetch_array($receiverler)) {
?>


<?=$row['receiver_markasi']?>
<?=$row['receiver_tipi']?>
<?=$row['receiver_ozelligi']?>
<?=$row['receiver_fiyati']?><?=$row['receiver_para_cinsi']?>






<?php
$sayi = 1;
while($sayi < $encok=$dairesayisi[‘secilen_daire_sayisi’]+1) {
echo ‘’.$sayi.’’;
$sayi++;
}
?>



<?php
}
?>
[/php]

step8.php code
[php]
$id = $_SESSION[‘lastid’];
for($i=0; $i<count($_POST[‘receiver_id’]); $i++) {
$receiver_id[] = $_POST[‘receiver_id’][$i];
$receiver_amount[] = $_POST[‘receiver_amount’][$i];
}
$values = array();
for($i=0; $i<count($receiver_id); $i++) {
$values[]="({$id}, {$receiver_id[$i]}, {$receiver_amount[$i]})";
}

      $receiver_amounts=mysql_query("INSERT INTO receiver_amounts (`id`, `receiver_id`, `receiver_amount`) VALUES " . implode(", ", $values));
      if (!$receiver_amounts)
     {
     die(mysql_error());
     }

[/php]

Again, thank you very, very much
Best Regards
Adem GENÇ

fixed the problem “”

Thank you so much for your help and interest.

Best Regards
Adem GENÇ

Sponsor our Newsletter | Privacy Policy | Terms of Service