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 8478597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:47:22+00:00 2026-06-10T18:47:22+00:00

My tex/csv file has 3 columns first_name , last_name and address but my database

  • 0

My tex/csv file has 3 columns first_name, last_name and address but my database table has two columns first_name and last_name. I wish to have a function that even there are many columns in csv that not exist in the table it still can just pick the right column and insert into table.
Some one advise me using php mysql_fetch_field. I am trying mysql_fetch_field and I can collect my database table columns name but I can’t insert data according to table header.

     set_time_limit(0);

    include "connection.php"; //Connect to Database


    if (isset($_POST['submit'])) {

    // Gel table current column name

    $query = "select * from month";
    $result=mysql_query($query) or die (mysql_error());

    $i = 0;
    while ($i < mysql_num_fields($result)) {
        $meta = mysql_fetch_field($result, $i);

        $a=$meta->name;

        $i++;
    }

    //Upload File

    if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
            echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
            echo "<h2>Displaying contents:</h2>";
            readfile($_FILES['filename']['tmp_name']);
        }

        //Import uploaded file to Database
        $handle = fopen($_FILES['filename']['tmp_name'], "r");

            $header = fgetcsv($handle);


        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $import="INSERT into month($header[0],$header[1]) values('$data[0]','$data[1]')";

            mysql_query($import) or die(mysql_error());
        }

        fclose($handle);

        echo "Import done";

    }
  • 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-06-10T18:47:23+00:00Added an answer on June 10, 2026 at 6:47 pm

    I’m not sure I get what you need but I think you should use MySQL Load Data Infile to load that CSV like this:

    LOAD DATA LOCAL INFILE 'your_file.csv'
    INTO TABLE your_table
    FIELDS TERMINATED BY ';'
    LINES TERMINATED BY '\r\n'
    (field1, field2, field3)
    

    That’s how I work with CSV and it does the job pretty well.

    Check this link.

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

Sidebar

Related Questions

Does LaTeX handle situation when a .bib file has different encoding than .tex file?
I have LaTeX code inside PHP (not as .tex file); for example received by
Inside a function I use to initialise some TeX related settings I have the
I have a file containing much TeX mark-up, like this: The fish ate 20\percent
I am writing a python script in order to write a tex file. But
I have a file, file1.tex , containing TeX commands, like \em and \par .
I have written autocmd! FileType tex set nonumber in my _vimrc (running Windows), but
I have multi-lingual TeX document mostly in Russian but I also include some terms
The name of the file is \033[A.tex. Note that the filename includes two times
in ~/.vimrc I have au BufNewFile,BufRead *.tex,*.md,*.markdown set spell but when I have open

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.