对于任何以后的人来说;我已经知道我的html页面正在发出打开php文件的请求,但它并没有发布任何数据。如果有人知道什么是错的,请告诉我。
到目前为止,这是我在前端所拥有的。
stackVar.push([place.name, websiteName, place.rating, place.international_phone_number, place.id, place.formatted_address, place.types[0]]);
//code for saving to a file will go here
if(results.length == stackVar.length){
var request = new XMLHttpRequest();
request.open('POST', 'http://www.server.com/saveF.php', true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.send(JSON.stringify(stackVar));
}
好的,所以我已经学到了一些东西,但我还没有完全在那里......就PHP来说,这就是我所拥有的......
<?php $conn = new mysqli($sn, $un, $pw, $db);
if ($conn->connect_error) {
die("connection failed: " . $conn->connect_error);
}
$bInfo = $_POST["stackVar"];
$infoEncoded = json_encode($bInfo);
$getsome = $infoEncoded[0][0];
$sql = "INSERT INTO companies(company) VALUES ('$getsome')";
echo $getsome;
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close()
?>