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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:29:17+00:00 2026-06-16T21:29:17+00:00

so, I have this users list which I get it from a csv file.

  • 0

so, I have this users list which I get it from a csv file.

What I need to do is this:
I get the file to upload, I check for each line if the user exists, if he does then all I do is update him, if he doesn’t I should create a new account for him.

I do know how to do it as a logic… but I become confused while using the csv import…

So, here it is what I use:

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

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $import="INSERT into users (Username,Password,Email,first_name,last_name,phone,user_id,age,sex) values('$data[0]','".md5($data[1])."','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]')";
    mysql_query($import) or die(mysql_error());
}

fclose($handle);

What I need is something like this:

foreach (user as $data[7]) {
    if user exists in user table then $query1 
    else $query2    
}

Thanks

  • 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-16T21:29:18+00:00Added an answer on June 16, 2026 at 9:29 pm

    MySQL has a handy little function called LOAD DATA INFILE, which allows it to load CSV files directly, without you needing to do the insert loop in PHP.

    You entire code could be as simple as this:

    $import="LOAD DATA INFILE '{$_FILES['filename']['tmp_name']}' INTO users (Username,Password,Email,first_name,last_name,phone,user_id,age,sex)";
    mysqli_query($connection, $import) or die(mysqli_error($connection));
    

    See the MySQL manual page here: http://dev.mysql.com/doc/refman/5.1/en/load-data.html

    note: I haven’t tested the above. If MySQL doesn’t have direct read access to the temp file, you may need to move it to a location the MySQL can read first, or use LOAD DATA LOCAL INFILE instead.

    note2: I’m using mysqli_xxx() functions instead of mysql_xx() because the mysql_xx() functions are deprecated. Feel free to change it back if you need to, but be aware that mysql_xx() is not recommended for use. I suggest you change all your mysql_xx() calls to mysqli_xxx() as soon as convenient.

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

Sidebar

Related Questions

I have a dictionary, user_dict, and create a list for each user value, this
I have this script that collects data from users and I want to check
I have this line: @users = database['users'].find(:all).limit(10) it returns this object: <Mongo::Cursor:0x8759a858 namespace='app-development.users' @selector=:all
I have this code App.Model('users').find(function (err, users) { users.forEach(function(user) { console.log(user.username); }); }); //make
I have this simple code in my user_controller.rb file #listing all users def index
I have this classes: public class User { [Key] public Guid UserId { get;
I have an application where I allow importing from CSV files. A list of
I have a Users table and a Payments table. I need a query which
Afternoon All, I have a dropdown list which extracts data from my SQL database
I have a list of users which I would like to send invite emails

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.