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:

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):
// 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); 
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 
            echo $data[3]." ";
            echo $data[4]."    ";
            echo "\n";
    } while ($data = fgetcsv($handle)); 
    header('Location: csvimportdomains.php?success=1'); die; 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
<html xmlns=""> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Import a CSV File with PHP & MySQL</title> 


<?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" /> 



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 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...

 How to add a cookie bar to WHMCS

In order to add a cookie bar to your own installation of WHMCS: copy somewhere on your WHMCS...