Hi, I’ve done a lot of searching and thus far have not found the resolution to my code error: Warning: json_decode() expects parameter
1 to be string, array given in C:\xampp\htdocs\testing…any help?
[php]<?php
function _NewDB()
{
try
{
$databaseName = “root”;$databaseUser = “homedb”;$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”, “number1”, “opvalue”, “number2”, “total” ); if(!$_POST) exit(“No data submitted via POST!”);
$data = json_decode($_POST, true); [b] // *** error line ***
[/b]
foreach($fieldList as $field)
if(!$data[$field]) exit(“No data submitted for '” . $field . “’!”);
$stmt = $dbh->prepare(“INSERT INTO calculator (purpose, number1, opvalue, number2, total) VALUES(:number1, :number2, :total, :opvalue, :purpose)”);
$stmt->execute($_POST);
echo ‘Sucessfully added a new row to the calculator table!’;
// Below pulling rows/results from the table with PDO
//$stmt = $dbh->prepare(“SELECT * FROM calculator”);
//$stmt->execute();
//$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
header( “refresh:3;url=‘http://localhost/testing/pdocalc.html’”);
?>
[/php]