My WHMCS version is 7. I have a drop down containing the list of clients. For getting the client list I'm using Capsule manager. On Selecting a client from drop down I have another db queries based on it. For that I added the following js in script.js file.
jQuery(document).ready(function ($) {
$('#clientList').on('change', function () {
var clientId = this.value;
$.ajax({
url: "/modules/addons/test/test.php",
type: "POST",
data: {clientId: clientId},
success: function (data) {
console.log(data);
}
});
});
});
in test.php file I added the following code
if (isset($_POST['clientId'])) {
try {
$clientList = Capsule::table('customtable')
->select('*')
->get();
} catch (\Exception $e) {
$error = "Error: {$e->getMessage()}";
echo $error;
}
}
Problem is, here on using capsule im getting 500 internal server error. How to access DB.
I added require_once '/var/www/mysite/init.php';
at the top of my test.php file. And now everything works like charm.