<分区>
所以我有一个后端代码,我在其中将数据库中的结果作为数组 Jobject 回显,还有一个代码(我将首先显示),当我想在我的数据库上创建一些东西时,我会尝试让一些事情发生通过我的前端。
所以我的问题是,我应该如何调整代码的第一部分,以便我的前端代码可以访问它,以便用户在前端代码中输入的信息进入数据库?
<?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();
?>
最后这是我的前端代码 (C#),我尝试访问数据库和我的 PHP 代码并从我的前端在我的数据库中创建一些东西:
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;
}
更新代码:
$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;