我使用了localhost
,并且一切正常,但是,当我将其托管在数字海洋中时,某些POST
函数不会写入mysql数据库。
我尝试使用Postman
来测试代码,它返回200 OK
和error writing to database
。
我的db_functions
代码:
public function insertNewListing($name,$imgPath,$price,$listingId,$descriptions,$packageOne,$packageTwo,$moreDescriptions,$itinerary,$imgPathTwo,$imgPathThree)
{
$stmt= $this->conn->prepare("INSERT INTO `Longhouses`(`Name`, `Link`,`Price`,`ListingId`,`descriptions`,`PackageOne`,`PackageTwo`,`MoreDescription`,`Itinerary`,`ImageTwo`,`ImageThree`) VALUES (?,?,?,?,?,?,?,?,?,?,?)") or die ($this->conn->error);
$stmt->bind_param("sssssssssss",$name,$imgPath,$price,$listingId,$descriptions,$packageOne,$packageTwo,$moreDescriptions,$itinerary,$imgPathTwo,$imgPathThree);
$result = $stmt->execute();
$stmt->close();
if($result)
return true;
else
return false;
}
我的add_listing
函数:
<?php
require_once '../../db_functions.php';
$db = new DB_Functions();
if(isset($_POST['name'])&&isset($_POST['imgPath'])&&isset($_POST['price'])&&isset($_POST['listingId'])&&isset($_POST['descriptions'])&&isset($_POST['packageOne'])&& isset($_POST['packageTwo'])&&isset($_POST['moreDescriptions'])&& isset($_POST['itinerary'])&& isset($_POST['imgPathTwo'])&& isset($_POST['imgPathThree']))
{
$name = $_POST['name'];
$imgPath = $_POST['imgPath'];
$price = $_POST['price'];
$listingId = $_POST['listingId'];
$descriptions = $_POST['descriptions'];
$packageOne = $_POST['packageOne'];
$packageTwo = $_POST['packageTwo'];
$moreDescriptions = $_POST['moreDescriptions'];
$itinerary = $_POST['itinerary'];
$imgPathTwo = $_POST['imgPathTwo'];
$imgPathThree = $_POST['imgPathThree'];
$result = $db->insertNewListing($name,$imgPath,$price,$listingId,$descriptions,$packageOne,$packageTwo,$moreDescriptions,$itinerary,$imgPathTwo,$imgPathThree);
if($result)
echo json_encode("ADD LISTING SUCCESFUL");
else
echo json_encode("error writing to database");
}