You probably have your notices turned off.
You have a multidimensional array, so you will have to access deeper before you can implode.
See your trouble:
$_SESSION['Sql']=[[1,'Kent Mercer',53],[2,'Linda Carter',63]];
var_export(implode(',',$_SESSION['Sql']));
Output:
<br />
<b>Notice</b>: Array to string conversion in <b>[...][...]</b> on line <b>5</b><br />
<br />
<b>Notice</b>: Array to string conversion in <b>[...][...]</b> on line <b>5</b><br />
'Array,Array'
How to prepare your data for the INSERT query:
Code: (Demo)
$_SESSION['Sql']=[[1,'Kent Mercer',53],[2,'Linda Carter',63]];
$str = implode(',', array_map(function($a){return "({$a[0]},'{$a[1]}',{$a[2]})";},$_SESSION['Sql']));
// wrap each row of data in its own set of parentheses
// this assumes that `id` and `age` are expecting numbers, and `name` is expecting a string.
echo "These are the parenthetical values:\n";
echo $str;
echo "\n\nQuery: INSERT INTO `test2` (`id`,`name`,`age`) VALUES $str";
// for best practice, wrap your tablename and columns in backticks.
// NAME is a mysql keyword
Output:
These are the parenthetical values:
(1,'Kent Mercer',53),(2,'Linda Carter',63)
Query: INSERT INTO `test2` (`id`,`name`,`age`) VALUES (1,'Kent Mercer',53),(2,'Linda Carter',63)
The next step in your learning is mysqli prepared statements with placeholders
for security reasons.
Here is a snippet that has built-in error checking with the statement preparation, binding, and execution so that you can isolate any issues. (I didn't test this before posting, if there are any problems please leave a comment. I don't want anyone copying a typo or flawed piece of code.)
Code:
$_SESSION['Sql']=[[1,'Kent Mercer',53],[2,'Linda Carter',63]];
if(!($stmt=$mysqli->prepare('INSERT INTO `test2` (`id`,`name`,`age`) VALUES (?,?,?)'))){ // use ?s as placeholders to declare where the values will be inserted into the query
echo "<p>Prepare failed: ",$mysqli->error,"</p>"; // comment this out or remove error details when finished testing
}elseif(!$stmt->bind_param("isi",$id,$name,$age)){ // assign the value types and variable names to be used when looping
echo "<p>Binding failed: (",$stmt->errno,") ",$stmt->error,"</p>"; // comment this out or remove error details when finished testing
}else{
foreach($_SESSION['Sql'] as $i=>$row){
list($id,$name,$age)=$row; // apply the $row values to each iterated execute() call
if(!$stmt->execute()){ // if the execute call fails
echo "<p>Execute failed: (",$stmt->errno,") ",$stmt->error,"</p>"; // comment this out or remove error details when finished testing
}else{
echo "<p>Success on index $i</p>"; // Insert was successful
}
}
}