I have a basic form that submits data through an ajax call. The data is intercepted with php to insert in mysql database. The problem is that the prepared sql statement only submits the last value in the array sent from the ajax call. How can I submit all values ? More details in the array sent through ajax: http://3v4l.org/Jqd6U#v540
data[0][firstName] James
data[0][lastName] Smith
data[1][firstName] Jane
data[1][lastName] Doe
data[2][firstName] Bob
data[2][lastName] Builder
etc..
$s = 1;
while(isset($_POST['data'][$s]['firstItem'])){
$person_fname = $_POST['data'][$s]['firstName'];
$person_lname = $_POST['data'][$s]['lastName'];
$query_init2 = "INSERT INTO person ( first_name, last_name) VALUES (:person_fname,:person_lname);";
$query_prep2 = $db_con->prepare($query_init2);
$insert_result2 = $query_prep2->execute(array(
"person_fname" => $person_fname,
"person_lname" => $person_lname
));
$s++;
}
foreach($_POST['data'] as $key => $value){
$f_name = $value['firstName'];
$l_name = $value['lastName'];
//insert here.
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments