I've spent the past 10 or so days trying to fix this to some success but I'm still stuck. I'm making an online budgeting system which takes Javascript values, sends them via Ajax to PHP where they are then sent to a database. Here is my code for javascript
$.ajax({
url: 'yup.php',
type:'post',
data:{
'Sal': Sal,
'TaxReb': TaxReb,
'RetInv': RetInv,
'IntSave': IntSave,
'Pen': Pen,
'Dividends': Dividends,
'Wages':Wages,
'Loans':Loans,
'Benefits':Benefits,
'IncOther': IncOther,
'Tax': Tax ,
'Groc': Groc ,
'Take':Take ,
'Rent': Rent ,
'Elec': Elec ,
'Trans': Trans ,
'Mort': Mort ,
'LoanPay':LoanPay ,
'Goods': Goods ,
'ExpOther': ExpOther ,
'TotalInc':TotalInc ,
'TotalExp': TotalExp ,
'NetInc':NetInc
},
success: function(data){
alert(data);
window.location.href='yup.php';
}
});
The values are integers which are working on the Jscript file. The alert gives me this message:
Array(
[Sal] => 33245
[TaxReb] => 324523
[RetInv] => 3245
[IntSave] => 2345
[Pen] => 3524
[Dividends] => 5342
[Wages] => 35425342
[Loans] => 5432
[Benefits] => 254325
[IncOther] => 4352
[Tax] => 34
[Groc] => 3434
[Take] => 34
[Rent] => 34
[Elec] => 34
[Trans] => 34
[Mort] => 34
[LoanPay] => 34
[Goods] => 34
[ExpOther] => 34
[TotalInc] => 36061675
[TotalExp] => 3740
[NetInc] => 36057935
)`
My PHP code is this:
<?php header(' charset=utf-8');
print_r($_POST)
//$Sal=$_POST['Sal'];
//echo $Sal;
However on my PHP page it gives me this: Array ( ) And when I uncomment the variables it gives me the error:
Notice: Undefined index: Sal in C:\xampp\htdocs\example\yup.php on line 2
I removed the print_r
when trying to get the actual variable.
When I use server request method the alert says post whereas the php page says get. This might be part of the problem but I have no idea how to fix it and neither did the other pages I looked at on this or other websites. All help is appreciated.