MySQL Forums
Forum List  »  Newbie

insert within loop
Posted by: Brian K
Date: February 19, 2014 03:51PM

I am trying to insert into MYSQL within a PHP loop.

I know I am submitting the right values to the stored procedure because I am printing them out to check. If I copy and paste the output into MYSQL and run them, then rows get entered. But, for some reason, running from within the loop, it only inserts one record. Here is the basic simplified code:

$val1 = 1;
$array = array(2, 3);

for ($i = 0; $i < count($array ); ++$i) {
echo "call sp_Insert(" . $val1 . ", " . $array . ")";
mysqli_query($link, "call sp_Insert(" . $val1 . ", " . $array . ")");
}

...as mentioned, it only inserts once, even thought I know it is looping through properly because I am printing out.

Any idea why this isn't working properly? As mentioned, if I copy the 2 outputs and paste/run them within MYSQL, the 2 rows both get entered.

Also, for some reason, this post doesn't show the square brackets for my $array values within the loop, but they are there.



Edited 1 time(s). Last edit at 02/19/2014 03:53PM by Brian K.

Options: ReplyQuote


Subject
Written By
Posted
insert within loop
February 19, 2014 03:51PM
February 19, 2014 04:39PM
February 19, 2014 05:07PM
February 19, 2014 06:34PM
February 19, 2014 07:24PM
February 19, 2014 07:29PM
February 20, 2014 10:36AM
February 24, 2014 11:02PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.