I'm at a loss (again) and wouldn't pass up some help.
below is the JS function w/variables (verified) that I'm trying to
send to PHP.
Code:
<FORM name="calculator" id="calculator"
action="http://localhost/home/webdev_insert.php" method="post">
...................................
Code:
function OnCalc(purpose,value1,op,value2,total)
{return(purpose,value1,op,value2,total);}
the message below tells me the variables didn't get passed:
Notice: Undefined index: data in C:\xampp\htdocs\home\webdev_insert.php on line 24
No data submitted for 'purpose'!
-------------------------------------
Code:
<?php
function _NewDB()
{
try
{
$databaseName = "homedb";
$databaseUser = "root";
$databasePass = "cookie";
$dbh = new PDO('mysql:host=localhost;dbname='.$databaseName, $databaseUser, $databasePass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{ error_log("PDOException: " . $e); return false; }
return $dbh;
}
// End connection stuff
$dbh = _NewDB();
$fieldList = array("purpose", "value1", "op", "value2", "total");
if(!$_POST) exit("No data submitted via POST!");
// ****************** line 24 below ******************
$data = json_decode($_POST['data'], true);
// ****************************************************
foreach($fieldList as $field) if(!$data[$field]) exit("No data submitted for '" . $field . "'!");
$stmt = $dbh->prepare
("INSERT INTO calculator ( purpose, value1, op, value2, total) VALUES(:purpose, :value1, :op, :value2, :total)");
$stmt->execute($data);
echo 'new row inserted';
// Below I'm pulling rows from the table
$stmt = $dbh->prepare("SELECT * FROM calculator");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
Bookmarks