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

  • SEARCH
  • Home
  • 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 6907887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:29:29+00:00 2026-05-27T08:29:29+00:00

is it possible to insert a csv file into a table and instruct the

  • 0

is it possible to insert a csv file into a table and instruct the query to always ignore the first row from the csv file. Users will be uploading files but the first row will be the column headings so I need the query to ignore the first row. My script looks like this at the moment:

<?php
include 'datalogin.php';

      move_uploaded_file($_FILES["fileCSV"]["tmp_name"],
      "quiz/" . $_FILES["fileCSV"]["name"]);

    $objCSV = fopen("quiz/".$_FILES["fileCSV"]["name"], "r");
        while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
        $strSQL = "INSERT INTO ex_question1 ";
        $strSQL .="(id,tn,qnr,qtype,pic,question,option1,option2,option3,option4) ";
        $strSQL .="VALUES ";
        $strSQL .="('".$objArr[0]."','".$objArr[1]."','".$objArr[2]."','".$objArr[3]."','".$objArr[4]."','".$objArr[5]."','".$objArr[6]."','".$objArr[7]."','".$objArr[8]."','".$objArr[9]."') ";
        $objQuery = mysql_query($strSQL);
    }
    fclose($objCSV);

    echo "Import completed.";
?> 
  • 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-27T08:29:30+00:00Added an answer on May 27, 2026 at 8:29 am

    Simply call fgetcsv($objCSV, 1000, ",") once before going into the loop:

     $objCSV = fopen("quiz/".$_FILES["fileCSV"]["name"], "r");
     fgetcsv($objCSV, 1000, ","); // skip first row
     while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
        $strSQL = "INSERT INTO ex_question1 ";
        $strSQL .="(id,tn,qnr,qtype,pic,question,option1,option2,option3,option4) ";
        $strSQL .="VALUES ";
        $strSQL .="('".$objArr[0]."','".$objArr[1]."','".$objArr[2]."','".$objArr[3]."','".$objArr[4]."','".$objArr[5]."','".$objArr[6]."','".$objArr[7]."','".$objArr[8]."','".$objArr[9]."') ";
        $objQuery = mysql_query($strSQL);
    }
    fclose($objCSV);
    

    NB. your code is prone to SQL injections, please escape your input variables properly or use prepared statements!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to insert a row into tablesorter that would always appear first
Is it possible to INSERT...ON DUPLICATE KEY UPDATE into a table on the current
Is it possible to insert into a table variable without defining the schema? I
In postgresql, I need to insert data to, say table B from sql query
Is it possible to insert into {% url %} field from queryset record? e.
Is it possible to insert more than one row in a table with one
I have a process that bulk inserts into a table from a CSV. I
Possible Duplicate: Insert line into a query result (sum) I have a report that
Is it possible to BULK INSERT (SQL Server) a CSV file in which the
In SQL Server , it is possible to insert rows into a table with

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.