0

i am try to insert Associative array in database which recieve it from ajax file . and when print it in console it be like {name: "name", number: "5"} .

$services_array = explode(',' ,$_REQUEST['services_array'] );
foreach ($services_array as $name => $quantity ) {
     $add_data   = $engine->connect()->query("INSERT IGNORE INTO `requests` SET 
        `section` = '$name',
        `quantity` = '$quantity '
        ");
}

the problem is in database the field of section the data in it be 0 or 1 or 2 and in field of quantity the data in it be [object Object]

CBroe
  • 91,630
  • 14
  • 92
  • 150

1 Answers1

0

looks for me that you just iterating over the rows, so your $name is your row index and your $quantity is the true object with contains the keys that you expecting, try to echo the $quantity object using:

var_dump($quantity);