这里我试图学习如何使用php + mysql作为后端来捕获来自这个离子ts文件的请求并将这些数据插入到表中。
我是一个带有离子+ php + mysql后端的总菜鸟。有人可以帮我解决一下吗?
createEntry(name, description)
{
let body : string = "key=create&name=" + name + "&description=" + description,
type : string = "application/x-www-form-urlencoded; charset=UTF-8",
headers : any = new Headers({ 'Content-Type': type}),
options : any = new RequestOptions({ headers: headers }),
url : any = this.baseURI + "add.php";
this.http.post(url, body, options)
.subscribe((data) =>
{
// If the request was successful notify the user
if(data.status === 200)
{
this.hideForm = true;
this.sendNotification(`Congratulations the technology: ${name} was successfully added`);
}
// Otherwise let 'em know anyway
else
{
this.sendNotification('Something went wrong!');
}
});
}
编辑:
我尝试了什么:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = $_REQUEST['name'];
$description = $_REQUEST['description'];
$sql = "INSERT INTO table1(name,description) VALUES($name, $desc)";
$result = $conn->query($sql);
echo json_encode ($desc);
值不会传递给表。