I am sending a javascript array by using jquery to a php script. In ajax I have a myarr variable but this variable can't be accessed in php. Error is :
Undefined index myarr
Please Please help me. this is really important.
This is my jquery code:
for (var n = 0; n < arraySubId.length; n++) { var ansArr = []; for (var m = 1; m <= 11; m++) { ansArr[m - 1] = $('#' + arraySubId[n] + '-' + m + '').val(); } * $.ajax({ type: 'POST', data: ({ 'sub_id': arraySubId[n], 'myarr': ansArr }), url: 'Scripts/insert_feedback.php', success: function(data) { if (data == "1") { } else { alert(data); } } }); * } When I access myarr variable in php, it's displaying:
Undefined index myarr.
Please Please help me.
And this is my php code:
<?php session_start(); $prn = $_SESSION['username']; $sub_id = $_POST['sub_id']; $ans_arr = $_REQUEST['myarr']; include 'dbclass.php'; $dbclass = new DBClass; $mysqli = $dbclass->connect(); $query = "INSERT INTO ".$sub_id."(student_prn, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, date) values('$prn', '$ans_arr[0]','$ans_arr[1]','$ans_arr[2]', '$ans_arr[3]','$ans_arr[4]','$ans_arr[5]','$ans_arr[6]', '$ans_arr[7]','$ans_arr[8]','$ans_arr[9]','$ans_arr[10]', now())"; $msg = $dbclass->insert($query); echo $msg; ?>