Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7073513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:56:19+00:00 2026-05-28T05:56:19+00:00

I have made the following script to upload a csv and import it into

  • 0

I have made the following script to upload a csv and import it into my MYSQL DB, this was my working test, it worked just fine. The problem came with the second example, I added all the fields too it to import but now its not doing a lot, its not giving any errors, it literally just prints the following to the page whenever I try to import anything now :

EDIT >>>>>>>

Is there a way I can turn the INSERT IGNORE message below into some kind of usable error message ?, as at the moment its just echoing the insert command instead of actually showing me any kind of error ?.

                        Import Successful : name
    - INSERT IGNORE hqfjt_chronoforms_data_addupdatelead (salutation, leadname, business, address, town, county, postcode, phone, email, gasoiluser,  dervuser, kerouser, annualconsgasoil, annualconsderv, annualconskero, gasoilmargin, dervmargin, keromargin, fueldetails, lubesdetails, otherdetails, sentletterday, sentlettermonth, sentletteryear, sentpostcardday, sentpostcardmonth, sentpostcardyear, sentquoteday, sentquotemonth, sentquoteyear, lastvisitedday, lastvisitedmonth, lastvisitedyear, receivegasoilmailinglist, receivedervmailinglist, receivekeromailinglist, gasoilmailinglist, dervmailinglist, keromailinglist, mailtype, createdby) VALUES ('salutation','name','business name','address','town','county','postcode','phone','email','gasoil user','derv user','kero user','annual consumption gas oil','annual consumption derv','annual consumption kero','gas oil margin','derv margin','kero margin','fuel details','lubes details','other details','sent letter day','sent letter month','sent letter year','sent postcard day','sent postcard month','sent postcard year','sent quote day','sent quote month','sent quote year','last visited day','last visited month','last visited year','mailtype','receive gasoil mailing list frequency','receive derv mailing list frequency','receivekero mailing list frequency','gasoil mailing list','derv mailinglist','kero mailinglist')

This was my initial testing code I used to check that the upload and import function was working properly :

    <?php
    //database connect info here

    //check for file upload
    if(isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['tmp_name'])){

        //upload directory
        $upload_dir = "./csv";

        //create file name
        $file_path = $upload_dir . $_FILES['csv_file']['name'];

        //move uploaded file to upload dir
        if (!move_uploaded_file($_FILES['csv_file']['tmp_name'], $file_path)) {

            //error moving upload file
            echo "Error moving file upload";

        }

        //open the csv file for reading
        $handle = fopen($file_path, 'r');


        while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) {

            //Access field data in $data array ex.
            $leadname = $data[0];
            $postcode = $data[1];
            $phone = $data[2];
            echo 'Import Successful : ';
            echo $leadname;
            echo '<br/>';

            //Use data to insert into db
            $sql = sprintf("INSERT IGNORE hqfjt_chronoforms_data_addupdatelead (leadname, postcode, phone) VALUES ('%s','%s','%s')",
                        mysql_real_escape_string($leadname),
                        mysql_real_escape_string($postcode),
                        mysql_real_escape_string($phone)
                        );
            mysql_query($sql) or (mysql_query("ROLLBACK") and die(mysql_error() . " - $sql"));
        }


        //delete csv file
        unlink($file_path);
    }
    ?>

I then went on and added all the fields…….now for some reason its not importing, and is just printing the message at the top of the page. I know I probably have missed something somewhere but I cant find it for the life of me.

    <?php
    //database connect info here

    //check for file upload
    if(isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['tmp_name'])){

        //upload directory
        $upload_dir = "./csv";

        //create file name
        $file_path = $upload_dir . $_FILES['csv_file']['name'];

        //move uploaded file to upload dir
        if (!move_uploaded_file($_FILES['csv_file']['tmp_name'], $file_path)) {

            //error moving upload file
            echo "Error moving file upload";

        }

        //open the csv file for reading
        $handle = fopen($file_path, 'r');


        while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) {

            //Access field data in $data array ex.
                        $salutation = $data[0];
                        $leadname = $data[1];                           
                        $business = $data[2];
                        $address = $data[3];
                        $town = $data[4];
                        $county = $data[5];
                        $postcode = $data[6];
                        $phone = $data[7];                          
                        $email = $data[8];
                        $gasoiluser = $data[9];
                        $dervuser = $data[10];
                        $kerouser = $data[11];
                        $annualconsgasoil = $data[12];
                        $annualconsderv = $data[13];
                        $annualconskero = $data[14];
                        $gasoilmargin = $data[15];
                        $dervmargin = $data[16];
                        $keromargin = $data[17];
                        $fueldetails = $data[18];   
                        $lubesdetails = $data[19];  
                        $otherdetails = $data[20];                          
                        $sentletterday = $data[21];
                        $sentlettermonth = $data[22];
                        $sentletteryear = $data[23];
                        $sentpostcardday = $data[24];
                        $sentpostcardmonth = $data[25];
                        $sentpostcardyear = $data[26];                          
                        $sentquoteday = $data[27];
                        $sentquotemonth = $data[28];
                        $sentquoteyear = $data[29];
                        $lastvisitedday = $data[30];
                        $lastvisitedmonth = $data[31];
                        $lastvisitedyear = $data[32];
                        $receivegasoilmailinglist = $data[33];
                        $receivedervmailinglist = $data[34];
                        $receivekeromailinglist = $data[35];
                        $gasoilmailinglist = $data[36];
                        $dervmailinglist = $data[37];
                        $keromailinglist = $data[38];   
                        $mailtype = $data[39];                      
                        $createdby = $data[40];

            echo 'Import Successful : ';
            echo $leadname;
            echo '<br/>';

            //Use data to insert into db
            $sql = sprintf("INSERT IGNORE hqfjt_chronoforms_data_addupdatelead (salutation, leadname, business, address, town, county, postcode, phone, email, gasoiluser, dervuser, kerouser, annualconsgasoil, annualconsderv, annualconskero, gasoilmargin, dervmargin, keromargin, fueldetails, lubesdetails, otherdetails, sentletterday, sentlettermonth, sentletteryear, sentpostcardday, sentpostcardmonth, sentpostcardyear, sentquoteday, sentquotemonth, sentquoteyear, lastvisitedday, lastvisitedmonth, lastvisitedyear, receivegasoilmailinglist, receivedervmailinglist, receivekeromailinglist, gasoilmailinglist, dervmailinglist, keromailinglist, mailtype, createdby) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
                        mysql_real_escape_string($salutation),
                        mysql_real_escape_string($leadname),                            
                        mysql_real_escape_string($business),
                        mysql_real_escape_string($address),
                        mysql_real_escape_string($town),
                        mysql_real_escape_string($county),
                        mysql_real_escape_string($postcode),
                        mysql_real_escape_string($phone),                           
                        mysql_real_escape_string($email),
                        mysql_real_escape_string($gasoiluser),
                        mysql_real_escape_string($dervuser),
                        mysql_real_escape_string($kerouser),
                        mysql_real_escape_string($annualconsgasoil),
                        mysql_real_escape_string($annualconsderv),
                        mysql_real_escape_string($annualconskero),
                        mysql_real_escape_string($gasoilmargin),
                        mysql_real_escape_string($dervmargin),
                        mysql_real_escape_string($keromargin),
                        mysql_real_escape_string($fueldetails), 
                        mysql_real_escape_string($lubesdetails),    
                        mysql_real_escape_string($otherdetails),                            
                        mysql_real_escape_string($sentletterday),
                        mysql_real_escape_string($sentlettermonth),
                        mysql_real_escape_string($sentletteryear),
                        mysql_real_escape_string($sentpostcardday),
                        mysql_real_escape_string($sentpostcardmonth),
                        mysql_real_escape_string($sentpostcardyear),                            
                        mysql_real_escape_string($sentquoteday),
                        mysql_real_escape_string($sentquotemonth),
                        mysql_real_escape_string($sentquoteyear),
                        mysql_real_escape_string($lastvisitedday),
                        mysql_real_escape_string($lastvisitedmonth),
                        mysql_real_escape_string($lastvisitedyear),
                        mysql_real_escape_string($mailtype),
                        mysql_real_escape_string($receivegasoilmailinglist),
                        mysql_real_escape_string($receivedervmailinglist),
                        mysql_real_escape_string($receivekeromailinglist),
                        mysql_real_escape_string($gasoilmailinglist),
                        mysql_real_escape_string($dervmailinglist),
                        mysql_real_escape_string($keromailinglist),                         
                        mysql_real_escape_string($createdby)
                        );
            mysql_query($sql) or (mysql_query("ROLLBACK") and die(mysql_error() . " - $sql"));
        }


        //delete csv file
        unlink($file_path);
    }
    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:56:19+00:00Added an answer on May 28, 2026 at 5:56 am

    This doesn’t work in PHP:

    mysql_query($sql) or (mysql_query("ROLLBACK") and die(mysql_error() . " - $sql"));
    

    two problems:

    • you don’t use “and” this way; create a control sturcture instead.

    • you are running the ROLLBACK command and then querying for the SQL error – that probably overrides mysql_error()‘s value.

    Try this for error handling:

    $error = mysql_query($sql);
    
    if (!$query) 
     { 
       echo mysql_error() . " - $sql";
       mysql_query("ROLLBACK"); 
       die();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have roughly the following code. Could this be made nicer or more efficient?
I have made a new windows service which works fine using barebone code (just
I have made the following search script but can only search one table column
The first part is now working [ I have the following which just seems
I have the following script which changes a jquery made object's color to blue:
Does someone have already made a script as following examples with YUI dataTable ?
I have created a sitecollection and in AAM I have made following settings for
I have a simple nav made up of the following HTML; <div class=inner> <div
I have an application that is made up of the following: A central database
I have a ruby script repeatedly executing the following the INSERT statement using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.