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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:48:25+00:00 2026-05-26T12:48:25+00:00

here is my scripts. if (isset($_POST[‘submit’])) { if (is_uploaded_file($_FILES[‘filename’][‘tmp_name’])) { echo <h1> . File

  • 0

here is my scripts.

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


$handle = fopen($_FILES['filename']['tmp_name'], "r");

     $header = fgetcsv($handle);

     while(! feof($handle)){

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

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

    }

fclose($handle);

echo "Done";

   }

This is the way how I insert data into database according to header even it’s not arranged same as the table column.
If the csv has only “cell,firstname,lastname,,” (and my table has only these 3 columns as well) then it still working…but if there are “cell,address,company,firstname,lastname” then it will show me unknown column error.

Actually 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.
Can anyone give me hints on how to change my script?I know there are many errors…it’s really embarrassed to show my low standard script…

Thanks in advance.

  • 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-26T12:48:25+00:00Added an answer on May 26, 2026 at 12:48 pm

    You would want to use mysql_fetch_field to get current columns, and then loop through each of your headers to ensure it exists in the table while building the query.

    http://php.net/manual/en/function.mysql-fetch-field.php

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

Sidebar

Related Questions

Here are the problem scripts: This is from the HTML file: <script type=text/javascript> var
I have a little problem with my if(isset($_POST['submit'])) code. What I want is some
I've got 256 colors working great in my terminal ( test scripts here ),
Here's my issue - I need to dynamically download several scripts using jQuery.getScript() and
Just wondering what little scripts/programs people here have written that helps one with his
Here is my script: #!/bin/bash echo Digite o local em que deseja instalar o
I found a multi file upload script here. When I try to upload the
Hey, can anyone notice any errors in this code: <?php include(config.php); if(isSet($_POST['lastmsg'])) { $lastmsg
$error1=''; $error2=''; $error3=''; $error4=''; $error5=''; $error6=''; $yourname=''; $email=''; $email2=''; $password=''; $password2=''; $country=''; if (isset($_POST['Registerme']))
I need a database for this: <?php if (isset($_POST['addcontentbox'])) { // Connection to Database

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.