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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:09:45+00:00 2026-05-26T07:09:45+00:00

I have a file I need to import into a database. (My database is

  • 0

I have a file I need to import into a database. (My database is good, I can connect and I can add). Now my problem is for some reason nothing gets inserted.

I have a file schooldatabase.txt of users/password I need to add to a database. The file has 200 lines.

Here’s a sample:

test|098f6bcd4621d373cade4e832627b4f6
test2|ad0234829205b9033196ba818f7a872b

Now for each of these line (student username and password) I have to insert them in a database.

Here’s my code:

function addUser($user,$pass) {
// this code is good
}

function processUser($user,$pass) {
  $pass=md5($pass);
  $myFile = "schooldatabase.txt";
  $fh = fopen($myFile, 'r');
  $theData = fread($fh, 5);
  $login = "$user|$pass";
  if(stristr($theData,$login) !== false){
      $result = "rejected";
  }
  elseif(stristr($theData,$login) !== true){
      addUser($user,$pass); // this work I manuall tested
      $result = "accepted";
   }
   fclose($fh);
   return $result;
}
var_dump(processUser('invaliduser','test2'));

Why it return “accepted” if that user is not in the file?

  • 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-26T07:09:45+00:00Added an answer on May 26, 2026 at 7:09 am

    I think here you should re-think about your process. I assume you “processUser” more than one time therefore you will open/read/close the same file over and over without altering that file.

    Because the file is not huge (and I assume it’s a one-time-script), Just open the file in memory when you start your script then you can compare all the value you are testing with that file.

    You can use the function file to do so. Then you can check if the user exists using in_array.

    Here’s the script:

    function addUser($user,$pass) {
    // this code is good
    }
    
    $file = file("schooldatabase.txt", FILE_IGNORE_NEW_LINES ^ FILE_SKIP_EMPTY_LINES);
    
    function processUser($user,$pass, array &$file) {
      $pass = md5($pass);
      if(in_array("$user|$pass", $file)) {
        addUser($user,$pass); // do you check if the query is good?
        return 'accepted';
      } 
      return "rejected";
    }
    
    var_dump(processUser('invaliduser','test2', $file));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel file that I need to import into a (new) Oracle
I have a PDF file, which contains data that we need to import into
I have a fixed-length data file need to persistence into database. I use a
I need to import the data form .csv file into the database table (MS
I have to import data from a CSV file into MySQL database using JSP/Servlet.
I have a .txt file that I need to include into a page, that
I need to import a csv file into Firebird and I've spent a couple
I'm trying to import a file into a database and learn a more efficient
I have an excel sheet I need to import in my Access database. The
I have a csv import file with 33 million lines that need to be

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.