Why is the $book variable empty? I’ve checked everything before it and up until that point everything is correct. I’ve even tried renaming it but that didn’t work
If I call the whole thing in a separate file using AJAX to submit the form it works but now it’s not. I understand what you’re saying about the execute_post function is empty but I don’t understand why or how to fix it?
<?php
//Function to initiate curl, set curl options, execute and return the response
function execute_post($url, $data){
//encode the data as json string
$requestBody = json_encode($data, true);
//initialise curl session
$ch = curl_init();
//curl options
curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_GETFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . 'application/json' ,'Content-Type: application/json'));
//curl execute and json decode the response
$responseBody = json_decode(curl_exec($ch));
//close curl session
curl_close($ch);
return $responseBody;
}
?>