So I'm trying to set POST data of a remote PHP script. This script uses the POST data as filename and retrieves a JSON file with it. But this sadly does not work. It retrieves the data with no values. Here is how it works:
C#:
using (WebClient client = new WebClient())
{
byte[] saveData = client.UploadData(
"http://" + ConfigurationManager.AppSettings["scripturi"].ToString() + "storeData.php",
"POST",
System.Text.Encoding.ASCII.GetBytes("filename="+ dt.bedrijfsNaam));
}
PHP:
<?php
$host='myip';
$user='username';
$pass='userpass';
$db='mydatabase';
$link= mysqli_connect($host, $user, $pass, $db) or die(msqli_error($link));
$filename = $_POST['filename'] . '.json';
$json = file_get_contents(__DIR__."/json/".$filename);// my thoughts are that something is wrong in this line?
$obj = json_decode($json);
$query_opslaan = "INSERT INTO skMain (BedrijfsName, ContPers, TelNum, email, Land, Plaats, PostCode) VALUES ('". $obj->bedrijfsNaam ."' , '". $obj->ContPers ."', '". $obj->TelNum ."', '". $obj->email ."', '". $obj->Land ."', '". $obj->Plaats ."', '". $obj->PostCode ."')";
mysqli_query($link, $query_opslaan) or die(mysqli_error($query_opslaan));
?>
it should retrieve correct data from the JSON file but instead it retrieves no values it all and the query stores blank data into the database. I think I used the C# script wrong and that's why I also think that the $json variable is not working correctly. But I don't exactly know what I did wrong. Can someone please help me?
ConfigurationManager.AppSettings["scripturi"].ToString()trueflag in$json = file_get_contents(__DIR__."/json/".$filename);