I want to save an array passed from Ajax to PHP to different columns of the table.
Here are the arrays that Ajax sends to PHP:
I get this on the browser network header after clicking the save button.
Form Data:
tableArray[0][]:awdawd
tableArray[0][]:awdawd
tableArray[0][]:Male
tableArray[0][]:<button class='delete'>Delete</button>
tableArray[1][]:awdaw
tableArray[1][]:awdwa
tableArray[1][]:Female
tableArray[1][]:<button class='delete'>Delete</button>
My problem is after clicking the save button it only saves the name part of the array to the table:

script:
$("#saveTable").click(function(){
$.ajax(
{
url: "saveTable.php",
type: "POST",
data: { tableArray: dataSet},
success: function (result) {
}
});
});
saveTable.php
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
$host = "localhost";
$user = "root";
$pass = "";
$db = "test";
$dbc = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$tableArray = $_REQUEST['tableArray'];
foreach( $tableArray As $v){
$sql = "INSERT INTO viewTables (name, age, gender, action) VALUES ('$v[0]','$[1]','$[2]','$[3]')";
$query = $dbc->prepare($sql);
$query->execute();
}
?>