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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:16:52+00:00 2026-06-09T13:16:52+00:00

I know there are other posts similar to this, but everyone recommends just doing

  • 0

I know there are other posts similar to this, but everyone recommends just doing it directly in PHPMyAdmin into MySQL (Which works perfectly, but I need to import through an HTML form to PHP to MySQL.

I would like to have an HTML form that collects a file. Then passes that file to a PHP script and I would like to know if it is possible to simply call a PHP function that converts a comma delimeted .csv file into MySQL and adds it to the database.

Or is the only way to parse the file line by line and add each record?

  • 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-09T13:16:53+00:00Added an answer on June 9, 2026 at 1:16 pm

    I haven’t fully tested this, but I don’t see any reason why it wouldn’t work.

    <?php
    
    if ( isset( $_FILES['userfile'] ) )
    {
      $csv_file = $_FILES['userfile']['tmp_name'];
    
      if ( ! is_file( $csv_file ) )
        exit('File not found.');
    
      $sql = '';
    
      if (($handle = fopen( $csv_file, "r")) !== FALSE)
      {
          while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
          {
              $sql .= "INSERT INTO `table` SET
                `column0` = '$data[0]',
                `column1` = '$data[1]',
                `column2` = '$data[2]';
              ";
          }
          fclose($handle);
      }
    
      // Insert into database
    
      //exit( $sql );
      exit( "Complete!" );
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
      <title>CSV to MySQL Via PHP</title>
    </head>
    <body>
      <form enctype="multipart/form-data" method="POST">
        <input name="userfile" type="file">
        <input type="submit" value="Upload">
      </form>
    </body>
    </html>
    

    Of course you would need to validate the data first.

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

Sidebar

Related Questions

I know there are other posts similar to this one, but none of them
I know there are many other posts on here with similar questions, but I
I know there are other questions that have similar issues, but I have read
I know that there are others posts with solutions on the site but i
I know and have Xcode, but I was wondering if there were any other
I know there is more than one question out there that matches this, but
I know that there is a post similar to this : here . I
I know there are a couple of similar questions(circular include) out stackoverflow and other
Does anyone know there have any other way that (by not using json_encode and
Or any other normal scripting language for that matter. I know there is VBScript

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.