php - AJAX function to insert a row in table is working but result is empty except when the insert fails

For some reason on just the INSERT sql query (in the data-controller.php), I can't seem to get any value from the 'result' (result is blank) although the table is getting populated with the appropriate values.
If the INSERT fails though, I get result as 'false' but I can never get a result = true. All other queries (not shown here) that deal with SELECT * and showing num_rows return result with the number of rows queried.
I followed this guy's guide to set all of this up - https://programmingfields.com/dropdown-selection-filter-in-php-using-jquery-ajax/
Here's my ajax code:
<<index.php>>
$.ajax({
url: './process-controller.php',
type: 'POST',
data: {
name: name, country: country, tech: tech, techsub: techsub, lia: lia
},
dataType: 'JSON',
success: function(result) {
alert(result);
}
})
Here's the code within the <<processcontroller.php>> file that's being called:
<?php
require_once 'data-controller.php';
if(isset($_POST['name'], $_POST['country'], $_POST['tech'], $_POST['techsub'], $_POST['lia'])) {
$name = $_POST['name'];
$country = $_POST['country'];
$tech = $_POST['tech'];
$techsub = $_POST['techsub'];
$lia = $_POST['lia'];
$dController = new DataController();
$insertquery = $dController->insertassetrecord($name,$country,$tech,$techsub,$lia);
echo json_encode($insertquery);
}
?>
And finally, here's the code for <<data-controller.php>>
<?php
include_once 'db-config.php';
class DataController {
public function insertassetrecord($insuredname, $country, $tech, $techsub, $lia) {
$db = new DBController();
$conn = $db->connect();
$sql = "INSERT INTO tbl_Assets (A_AssetID,A_InsuredName,A_CountryID,A_TechnologyID,A_TechSubTypeID,A_LendersInsuranceAdvisorID) VALUES ('0','$insuredname','$country','$tech','$techsub','$lia')";
$result = $conn->query($sql);
$db->close($conn);
return $result;
}
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illegal string offset
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.