0

I'm trying to do a multiple insert on a mysql table using prepared statements but it is not working as expected.

I do not get any error message.

I only get the first result into the table.

This is the relevant code

$array_of_data // contains all the information that I want to insert, I'm sure it's there.
$table = 'table_name';
$query = "INSERT INTO ".$table."( `some_id`, `name`, `last_name_1`, `last_name_2` ) VALUES ( ?, ?, ?, ? )";
$connection = conexion_mysql();
$init = mysqli_stmt_init( $connection );
$prepare = mysqli_stmt_prepare( $init, $query );
foreach ( $array_of_data as $keys => $values ) {
    $bind = mysqli_stmt_bind_param( $init, 'ssss', $values['some_id'], $values['name'], $values['last_name_1'], $values['last_name_2'] );
    $execute = mysqli_stmt_execute( $init );
}
unset( $keys, $values );

$close = mysqli_stmt_close( $init );
mysqli_close( $connection );

I have checked some other answers here and over the Internet but it seems that I'm still doing something wrong

The system I'm workning on has

  • PHP 5.4.16 (yes I should upgradde that but I can't) MySQL
  • 5.5.56-MariaDB (can't change it either but it's not too bad)
PatomaS
  • 1,603
  • 18
  • 25
  • 2
    Why do you assign all these into `$tmp`? – Qirel Apr 02 '19 at 10:23
  • Either $array_of_data **does not** contain all the information that you want to insert, or all other inserts result in the error. I am closing this question with the generic reason but would reopen it if you will provide a [Minimal, Complete, and Verifiable example](https://phpdelusions.net/pdo/mcve) to prove your claim. – Your Common Sense Apr 02 '19 at 10:26
  • @Qirel, It's something that I do in most of my scripts to simplify some processes, for instance, I do a var_dump to know what is happening, I only have to do it on one variable, I can't forget any other related one. – PatomaS Apr 02 '19 at 10:59
  • @Your Common Sense The variable has all the values, I've seen them with a dump of the variable. I'll try to paste a dump of the variable later but it needs a lot of edditing of the data contained. – PatomaS Apr 02 '19 at 11:01

0 Answers0