so I have a php script(its name is wiadomosci.php) with following code:
<?php
if (isset($_GET['wszystkie'])) //when I'm sending GET with wszystkie? paramets it send back all records in JSON - it works without any problems
{
$con=mysqli_connect("xxxl","xxxx","xxxx","xxxl");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
mysqli_query("SET CHARSET utf8", $con);
mysqli_query("SET NAMES 'utf8' COLLATE 'utf8_bin'", $con);
$tablica_wynikow = array();
$pobrane_dane = mysqli_query($con, "SELECT * FROM wiadomosci");
while($nt=mysqli_fetch_assoc($pobrane_dane)){
$tablica_wynikow[] = $nt;
}
header('Content-Type: application/json');
echo json_encode($tablica_wynikow);
}
mysqli_close($con);
}
if (isset($_POST["nowa_wiadomosc"])) //hre is post part
{
$tresc_wiadomosci = $_POST["nowa_wiadomosc"];
$con=mysqli_connect("xxx","xxx","xxx","xxxx");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: ";
}
else
{
mysqli_query("SET CHARSET utf8", $con);
mysqli_query("SET NAMES 'utf8' COLLATE 'utf8_bin'", $con);
mysqli_query("INSERT INTO wiadomosci (tresc_wiadomosci) values ($tresc_wiadomosci)");
}
mysqli_close($con);
}
?>
And this is how I try to send POST from c# app:
System.Net.WebClient client = new System.Net.WebClient();
string result = client.UploadString("xxxxxxxx/wiadomosci.php?", "nowa_wiadomosc=TESTTTTT");
Console.WriteLine(result);
But as result I get some random webiste's html code and new record isn't added. If someone could point me in the right direction.
EDIT: ITS FIXED. I started debbuging it more and more and it was wrong query construction in php script, now everything works.
Thank You guys anyway.