0

I have looked at loads of other solutions for my problem on this but none seem to work. I'm trying to pass multiple JavaScript variables to Php. Currently, I'm trying it with Ajax:

$.ajax({
   url: "yup.php",
   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},
 type:"post",
 success:function(output){
   alert(output);
   //window.location.href='yup.php',

These variables have numeric values attached to them( checked, their not the problem). I've named it yup because it's just for testing purposes. Using alert it outputs exactly what I want it to, it pops up in a little window. However, when I actually go to the page I get undefined index errors.

Notice: Undefined index: Sal in C:\xampp\htdocs\example\yup.php on line 2

It does that for all the variables I'm trying to pass through. I've tried removing alert and function(output) but it doesn't change anything. I plan to write the PHP variables to a database afterward. Any help is appreciated. My Php is this:

<?php $Sal = $_POST['Sal'];
$TaxReb = $_POST['TaxReb'];
$RetInv = $_POST['RetInv'];
$IntSave = $_POST['IntSave'];
$Pen = $_POST['Pen'];
$Dividends = $_POST['Dividends'];
$Wages = $_POST['Wages'];
$Loans = $_POST['Loans'];
$Benefits = $_POST['Benefits'];
$IncOther = $_POST['IncOther'];
$Tax = $_POST['Tax'];
$Groc = $_POST['Groc'];
$Take = $_POST['Take'];
$Rent = $_POST['Rent'];
$Elec = $_POST['Elec'];
$Trans = $_POST['Trans'];
$Mort = $_POST['Mort'];
$LoanPay = $_POST['LoanPay'];
$Goods = $_POST['Goods'];
$ExpOther = $_POST['ExpOther'];
$TotalInc = $_POST['TotalInc'];
$TotalExp = $_POST['TotalExp'];
$NetInc = $_POST['NetInc'];
echo //all the variables;?><br>
LF00
  • 27,015
  • 29
  • 156
  • 295
Awtthem
  • 1
  • 4
  • try to debug $_POST like: `if(isset($_POST)) { foreach($_POST as $post=>$value) { print "$post : $value
    \n";}` . look, if Sal not empty in your ajax.
    – Eugen Dec 30 '16 at 20:31
  • Ok so I tried this, alert gave it in proper format as a pop up window but the yup page had nothing on it and gave the same error as before, suggesting it's not being sent? – Awtthem Dec 31 '16 at 15:37

0 Answers0