// database connection strings. change these to your DB and Table names.
$dbName = “a6474605_order”;
$tableName = “godfathersorder”;
// connect to the table
mysql_select_db(a6474605_order)or die(“cannot select DB”);
if (!$link) {
exit(‘Error: Could not connect to MySQL server!’);
}
// lets prepare some files to capture what is going on.
$incomingJson = ‘json.txt’;
//$fullArray = ‘fullArray.txt’; // needed if you enable the debugging secton below
$sqlErrorLog = “sqlErrors.txt”;
// initialize the string with a blank value
$string = “”;
// start SEND data
if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’) {
//capture incoming data
error_reporting(1);
$sig = $_POST["sig"];
$jsondata = $_POST["params"];
// this line captures the sent data so you can figure out what you need to send back.
file_put_contents($incomingJson,$jsondata);
// this line tells the application that the data send was successful.
echo '{"Status":"Success"}';
// convert JSON to an array
$array = json_decode($jsondata, TRUE);
/*
// formats the array to view it easier
$results = print_r($array,true);
file_put_contents($fullArray,$results);
*/
//get the total number of objects in the array
$arrlength = count($array['Children']['1']['Properties']);
// set while loop index
$i = 0;
//loop through array node and get row values
while ($i < $arrlength ) {
// get row value
$value = $array['Children']['1']['Properties'][$i]['Value']."\n";
// convert delimited string to an array
$arrayPieces = explode("|", $value);
// get array values. This section would have to be modified to capture each value you are interested in.
$rowName = $arrayPieces(0); // this variable will be blank if you don't name your rows.
$Pizza = $arrayPieces(1);
$STUFEDCRUST = $arrayPieces(2);
$MOREINFO = $arrayPieces(3);
$coldel = $arrayPieces(4);
$price = $arrayPieces(5);
$NAME = $arrayPieces(6);
$ADDRESS1 = $arrayPieces(7);
$ADDRESS2 = $arrayPieces(8);
$ADDRESS3 = $arrayPieces(9);
$POSTCODE1 = $arrayPieces(10);
$POSTCODE2 = $arrayPieces(11);
$PHONE = $arrayPieces(12);
mysqli_select_db("godfathersorder", $link)
// construct SQL statement
$sql="INSERT INTO godfathersorder(Pizza, STUFEDCRUST, MOREINFO, coldel, price, NAME, ADDRESS1, ADDRESS2, ADDRESSS3, POSTCODE1, POSTCODE2,PHONE)VALUES('$Pizza', '$STUFEDCRUST', '$MOREINFO', '$coldel', '$price', '$NAME', '$ADDRESS1', '$ADDRESS2', '$ADDRESS3', '$POSTCODE1', '$POSTCODE2', '$PHONE')";
// insert SQL statement
$result=mysql_query($sql);
// catch any errors
if($result){
// if successful do nothing for now.
}
else {
// if failure, write to custom log
$sqlError = "Error writing to database\n";
file_put_contents($sqlErrorLog, $sqlError, FILE_APPEND);
}
$i++;
}
} // end of POST
?>
please help the insert into table does not seem to work as there is nothing going into mysql tabe the code leaves a json.text file to show the first part working but does not seem to put the contents into my table.
please please help