karnadesai Posted September 15, 2011 Share Posted September 15, 2011 I have successfully installed whmcs on linux server and also am able to add a client using whmcs admin section but when i try to access whmcs using api i get the following error Critical Error Could not connect to the database I have checked that the user is assigned for the corresponding whmcs database my code is below <?php ini_set('display_errors',1); error_reporting(E_ALL); #$url = "http://localhost/whmcs/includes/api.php"; # URL to WHMCS API file $whmcsurl= "http://localhost/whmcs/includes/api.php"; # URL to WHMCS API file $whmcsadminusername= "root"; # Admin username goes here $whmcsadminpassword= "desai"; # Admin password goes here $postfields["username"] = $whmcsadminusername; $postfields["password"] = md5($whmcsadminpassword); $postfields["action"] = "addclient"; $postfields["firstname"] = "Test123"; $postfields["lastname"] = "User123"; $postfields["companyname"] = "WHMCS"; $postfields["email"] = "demo@whmcs.com"; $postfields["address1"] = "123 Demo Street"; $postfields["city"] = "Demo"; $postfields["state"] = "Florida"; $postfields["postcode"] = "AB123"; $postfields["country"] = "US"; $postfields["phonenumber"] = "123456789"; $postfields["password2"] = "demo"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $whmcsurl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); echo $data; $data = explode(";",$data); foreach ($data AS $temp) { $temp = explode("=",$temp); //$key = strtok($temp, "="); //$v = strtok($temp); echo "hi \n".$temp[0]." ".$temp[1]; $results[$temp[0]] = $temp[$temp[1]]; } if ($results["result"]=="success") { echo "User Generated Successfully<br /> <br />"; } else { # An error occured echo "The following error occured: ".$results["message"]; } ?> 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.