I am posting serialized data using this function:
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
console.log($( this ).serialize());
var data = $( this ).serialize();
$.ajax({
type: "POST",
url: "content/rev/a_submit.php",
data: "data=" + data,
success: function(result){
$("#acct_content").html(result);
}
});
});
the console.log of the data matches what is in the form:
month1%5B%5D=4&sap=721&name=uname&month1%5B%5D=10000.00&month2%5B%5D=10000.00&month3%5B%5D=0.00&month4%5B%5D=&month5%5B%5D=&month6%5B%5D=&month1%5B%5D=15000&month2%5B%5D=0.00&month3%5B%5D=0.00&month4%5B%5D=&month5%5B%5D=&month6%5B%5D=&month1%5B%5D=50&month2%5B%5D=50&month3%5B%5D=50&month4%5B%5D=&month5%5B%5D=&month6%5B%5D=&month1%5B%5D=15000&month2%5B%5D=10000&month3%5B%5D=0&month4%5B%5D=0&month5%5B%5D=0&month6%5B%5D=0&sap_data%5B%5D=&sap_data%5B%5D=&sap_data%5B%5D=&sap_data%5B%5D=
What I print_r the array on the php file I get:
Array ( [0] => 10000.00 [1] => 1 [2] => 50 [3] => 15000 )** Array ( [0] => 10000.00 [1] => 1 [2] => 50 [3] => 10000 ) Array ( [0] => 0.00 [1] => 1 [2] => 50 [3] => 0 ) Array ( [0] => [1] => [2] => [3] => 0 ) Array ( [0] => [1] => [2] => [3] => 0 ) Array ( [0] => [1] => [2] => [3] => 0 ) Array ( [0] => [1] => [2] => [3] => )
Th issue lies in the first array (month1). You can see that in the console.log for the 2nd index it shows:
month1%5B%5D=15000
but in the array it has [1] => 1
This happens for each month in that specific index.
I'm a little lost. Index 0 and 1 are handled the exact same way in my php code although only one is correctly getting put into the array...
edit: here is the html/php Getting the variables to pass:
$month1= mysql_query("SELECT conf_budget,incremental,round((confidence*100),0),(updated_at) FROM rev_acct WHERE sap_id = '$sap' AND MONTH = '$mb' ORDER BY updated_at DESC LIMIT 1;");
$row1 = mysql_fetch_row($month1);
$bud1 = $row1[0];
$inc1 = $row1[1];
$con1 = $row1[2];
The inputs in the form:
<td>$<input class="input-small" name="month1[]" id="conf1_<?php echo $sap; ?>" onkeypress="return isNumberKey(event)" type="text" value="<?php echo $bud1; ?>"></td>
<td>$<input class="input-small" name="month1[]" type="text" id="inc1_<?php echo $sap; ?>" onkeypress="return isNumberKey(event)" value="<?php echo $inc1; ?>" ></td>
EDIT2: adding sumbit code
$month1 = array();
$month1 = $_POST['month1'];
print_r($month1);
I just var dumped the array and index one is a bool for some reason. The value originally comes from a mysql table where its stored as a decimal. (the same as index 0), yet when I post it it comes in as a bool :\
console.logdata, but... aren'tmonth1%5B%5D,&month1%5B%5D=10000.00, etc. the same parameter? That would explain why one would be written while another is overwritten...a_submit.phpto get and idea of how you're parsing and decoding thedata.