simple php script to barely import domain records into WHMCS

If the number of domains to be imported in your WHMCS is not huge (i.e., less than 200 domains), the best and simplest way to do it is manually, as explained here:  https://docs.whmcs.com/Importing_Data#Manual_Domain_Only_Entry

If you have a large number of domain to import in your WHMCS system, you can do it as follows:

  1. organize your domains in a CSV file (formatting detail in the following code)
  2. import your CSV file using following script (to be copied into your /admin/ directory):
<?php  
// csvimportdomains.php
// very simple php script to barely import domain records in WHMCS
//
// * separator used in csv file must be comma
// * fields in csv must be as follows:
//    userid
//    type 
//    registrationdate
//    domain
//    firstpaymentamount
//    recurringamount
//    registrar
//    registrationperiod
//    expirydate
//    status
//    nextduedate
//   	paymentmethod
//connect to the database 
$db_host = 'localhost';
$db_username = 'dbusername';
$db_password = 'dbpassword';
$db_name = 'dbname';
$connect = mysql_connect($db_host,$db_username,$db_password); 
mysql_select_db($db_name,$connect);       
// 
if ($_FILES[csv][size] > 0) { 
    //get the csv file 
    $file = $_FILES[csv][tmp_name]; 
    $handle = fopen($file,"r"); 
     
    //loop through the csv file and insert into database 
    do { 
        if ($data[0]) { 
            mysql_query("INSERT INTO tbldomains (userid, type, registrationdate, domain, firstpaymentamount, recurringamount, registrar, registrationperiod, expirydate, status, nextduedate, 	paymentmethod ) VALUES 
                ( 
                    '".addslashes($data[0])."', 
                    '".addslashes($data[1])."',
                    '".addslashes($data[2])."',
                    '".addslashes($data[3])."',
                    '".addslashes($data[4])."',
                    '".addslashes($data[5])."',
                    '".addslashes($data[6])."',
                    '".addslashes($data[7])."',
                    '".addslashes($data[8])."',
                    '".addslashes($data[9])."',
                    '".addslashes($data[10])."',
                    '".addslashes($data[11])."' 
                ) 
            ");
            echo $data[3]." ";
            echo $data[4]."    ";
            echo "\n";
        } 
    } while ($data = fgetcsv($handle)); 
    // 
    //redirect 
    header('Location: csvimportdomains.php?success=1'); die; 
} 
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Import a CSV File with PHP & MySQL</title> 
</head> 

<body> 

<?php if (!empty($_GET[success])) { echo "<b>Your file has been imported.</b><br><br>"; } //generic success notice ?> 

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
  Choose your file: <br /> 
  <input name="csv" type="file" id="csv" /> 
  <input type="submit" name="Submit" value="Submit" /> 
</form> 

</body> 
</html>

 

Warning!
This script works directly on database, bypassing any WHMCS check. So:

  •  put your WHMCS in maintenance mode before running it
  • check that every TLD extension you're going to import still exists and is defined in your WHMCS  (Setup => Product/Services => Domain Pricing )
  • check that every userid you're going to use in the CSV file still exists in your WHMCS

  • WHMCS, php
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How to reduce the number of available languages in WHMCS

WHMCS comes with a lot of available languages for its interface, few of them also quite exotic.So...

How to add a favicon in WHMCS

To add a favicon to your WHMCS install: copy your favicon (es. myfavicon.ico) in WHMCS folder...

How to comment in template (.tpl) files

If you need to insert a comment in a .tpl file, or comment a block of code to disable it, you...

How to insert a Youtube video in WHMCS knowledgebase article

To insert a YouTube video in an article of the WHMCS knowledge base, you need to insert following...

How to disable a customer to pay invoices partly with credit balance

in WHMCS if a customer has not enough credit balance for full payment of an invoice, WHMCS allows...