So I hava an app which creates a JSON file with some data from the user. This data should be decoded and stored to the database through a PHP script located on my server. I want to post the $_POST variable filename to the php script to use this to retrieve the JSON file. Here is my current PHP script:
<?php
$host='myip';
$user='username';
$pass='userpass';
$db='database';
$link= mysqli_connect($host, $user, $pass, $db) or die(msqli_error($link));
$filename = $_POST['filename'] . '.json';
$json = file_get_contents($filename);
$obj = json_decode($json,true);
foreach ($obj as $data)
{
$query_opslaan = "INSERT INTO skMain (BedrijfsName, ContPers, TelNum, email, Land, Plaats, PostCode) VALUES ('". $data['bedrijfsNaam'] ."' , '". $data['ContPers'] ."', '". $data['TelNum'] ."', '". $data['email'] ."', '". $data['Land'] ."', '". $data['Plaats'] ."', '". $data['PostCode'] ."')";
}
?>
And this is my JSON file
{
"bedrijfsNaam":"JohnDoeMedia",
"ContPers":"John Doe",
"TelNum":"1234567890",
"email":"test@test.nl",
"Land":"Nederland",
"Plaats":"somewhere",
"PostCode":"1234 AB"
}
I currently only have the upload script in C# but I don't know how to use it to run this PHP script and store data to the PHP variable $_POST['filename'] Here is the store script:
WebRequest hwr = WebRequest.Create(serverPath);
hwr.Method = WebRequestMethods.Ftp.UploadFile;
hwr.Credentials = new NetworkCredential(ftpUser, ftpPass);
if (reqCat == "bvg")
{
json = "{\"bedrijfsNaam\":\"" + bedrijfsNaam + "\"," +
"\"ContPers\":\"" + ContPers + "\"," +
"\"TelNum\":\"" + TelNum + "\"," +
"\"email\":\"" + email + "\"," +
"\"Land\":\"" + Land + "\"," +
"\"Plaats\":\"" + Plaats + "\"," +
"\"PostCode\":\"" + PostCode + "\"}";
using (var sw = new StreamWriter(hwr.GetRequestStream()))
{
sw.Write(json);
sw.Flush();
sw.Close();
}
}
Can someone please teach me the method to make this work?