So I have a backend code where I echo out the results in my database as an array Jobject and also a code (that iam going to show first) where I try to make something happen when I want to create something on my DB via my frontend.
So my question is, How should I adjust the first part of the code so my frontend code can reach it and so that the info that the user puts in the frontcode gets into the database?
<?php
$mysql_pekare= new mysqli ("host", " user","pass", "db");
$stmt = $mysql_pekare->prepare("INSERT INTO Events(`Name`, `Title`) VALUES(?,?)");
$stmt->bind_param("ss", $namn, $age);
$stmt->execute();
$stmt->close();
$mysql_pekare->close();
?>
And finally this is my frontend code (C#) where I try to reach the DB and my PHP-code and create something into my DB from my frontend:
static public async Task <bool> createOurMainInfo (string userId, string thename, string thetitle)
{
var httpClientRequest = new HttpClient ();
var postData = new Dictionary <string, string> ();
postData.Add ("Name", thename);
postData.Add ("Title", thetitle);
var jsonRequest = JsonConvert.SerializeObject(postData);
HttpContent content = new StringContent(jsonRequest, System.Text.Encoding.UTF8, "application/json");
var result = await httpClientRequest.PostAsync("http://localhost/Events.php", content);
var resultString = await result.Content.ReadAsStringAsync ();
return true;
}
Updated code:
$value1 = json_decode(file_get_contents('php://input'));
$value2 = json_decode(file_get_contents('php://input'));
$mysql_pekare= new mysqli ("", "","", "");
$stmt = $mysql_pekare->prepare("INSERT INTO Events(`Name`, `Title`) VALUES(?,?)");
$stmt->bind_param("ss", $value1, $value2);
$stmt->execute();
$stmt->close();
$mysql_pekare->close();
echo $value1->Name;
echo $value2->Title;