I used localhost
and everything works fine, however, when I hosted it in digital ocean, certain POST
functions don't write to the mysql database.
I've tried using Postman
to test the code, and it returns 200 OK
and error writing to database
.
My db_functions
code:
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;
}
My add_listing
function:
<?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");
}