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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:19:32+00:00 2026-06-01T06:19:32+00:00

ok all I want to do is give the user a simple form where

  • 0

ok all I want to do is give the user a simple form where they can upload a CSV file which contains fares. The data should then upload into the database.

Here’s the code…

<?php
 require_once('includes/connection.php');
 if(isset($_POST['submit']))
   {
     $filename=$_POST['filename'];
     $handle = fopen("$filename", "r");
     while (($data = fgetcsv($handle, 100000, ",")) !== FALSE)
     {

       $import="INSERT into fares_usa(cruise_id, active, type, category, placement, deck, fare, offered, status, sortorder)          values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]')";
       mysql_query($import, $connection) or die(mysql_error());
     }
     fclose($handle);
     print "Import done";
   }
   else
   {

      print "<form enctype='multipart/form-data' action='fileupload.php' method='POST'>";
      print "Select file to import:";
      print "<input type='file' name='filename' size='20'>";
      print "<input type='submit' name='submit' value='submit'></form>";
   }
   ?>

Any help is greatly appreciated !

Thanks

Rich 🙂

  • 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-01T06:19:34+00:00Added an answer on June 1, 2026 at 6:19 am

    You seem to be using $_POST and not $_FILES

    <?php
     require_once('includes/connection.php');
     if(isset($_POST['submit']))
       {
         $filename=$_FILES['filename']['tmp_name'];
         $handle = fopen("$filename", "r");
         while (($data = fgetcsv($handle, 100000, ",")) !== FALSE)
         {
    
           $import="INSERT into fares_usa(cruise_id, active, type, category, placement, deck, fare, offered, status, sortorder) 
           values('".mysql_real_escape_string($data[0])."',
           '".mysql_real_escape_string($data[1])."',
           '".mysql_real_escape_string($data[2])."',
           '".mysql_real_escape_string($data[3])."',
           '".mysql_real_escape_string($data[4])."',
           '".mysql_real_escape_string($data[5])."',
           '".mysql_real_escape_string($data[6])."',
           '".mysql_real_escape_string($data[7])."',
           '".mysql_real_escape_string($data[8])."',
           '".mysql_real_escape_string($data[9])."')";
           mysql_query($import, $connection) or die(mysql_error());
         }
         fclose($handle);
         print "Import done";
       }
       else
       {
    
          print "<form enctype='multipart/form-data' action='fileupload.php' method='POST'>";
          print "Select file to import:";
          print "<input type='file' name='filename' size='20'>";
          print "<input type='submit' name='submit' value='submit'></form>";
       }
       ?>
    

    Also added mysql_real_escape_string to escape your input before adding it to the database. This is the bare minimum "cleaning" that you should be doing for user input.

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

Sidebar

Related Questions

I want to give credit to all open source libraries we use in our
All I want is a pragmatic random number generator in C# so I can
So I have a form that I want the user to use to update
My over all goal is to upload a very simple ASP.NET web site created
Is it possible to serialize an ASP.NET web form, including all data that a
I'm developing a simple app in which I want to maintain a session in
I've one object User which can have multiple Posts. Example: Load the user with
My ASP.NET MVC site allows users to register and give themselves user names, which
All I want is to be able to change the color of a bullet
All I want is to update an ListViewItem's text whithout seeing any flickering. This

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.