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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:32:36+00:00 2026-05-26T21:32:36+00:00

I am pretty new to both php and mysql. I have a txt file

  • 0

I am pretty new to both php and mysql. I have a txt file with a table on it that has each column seperated by a semi-colon column1;column2 and each row is on a new line in the txt file.

column1-row1;column2-row1

column1-row2;column2-row2

I am trying to upload the txt file to a mysql table using phpmyadmin. The first row goes in just fine, but the second one doesn’t. I have tried \r and \n and also \r\n but none of these are working. Those only drop the second result on the txt file to another line (not row) on the first mysql row. So everything is going into the first row on the mysql table.

I have also tried putting a semi-colon after the last column as well column1;column2; but all this does is stop after the fist row.

I guess I am asking how I format the txt file to make each line on the txt file start a new row in the sql table. Or maybe I need to set something up on phpmyadmin first. This is probably extremely easy, but again, I am very new to both php and sql. Thanks so much.


Okay, It’s the same issue I originally had. I have a database, and in that database I have a table with two columns ‘a’ and ‘b’. I also have a txt file I created already that has 50 rows of data. On the txt file, I have seperated ‘a’ and ‘b’ with a semicolon a;b and then I have hit return on my keyboard to make the next row of data. When I upload the txt file using either SQL or your PHP script and then browse the table on my database, it has only entered the first row from my txt file and after the ‘b’ in the first row (on my database table), it has started to enter the second row of data (from my txt file) on a new line but still the same row. I would like the second from my txt file to be placed in a new row on my database table. Maybe I can’t, but that’s the problem I am having.

This is the code I am using:

<?php
                                
$user_name = "username";
$password = "password";
$database = "database";
$server = "server";
                                
                                
                                
$db = mysql_connect($server, $username, $password);
            
            
if (!$db) {
    die('Could not connect: ' . mysql_error());
}

$fileHandle = fopen('my_text_file.txt', 'rb');

while (!feof($fileHandle)) {
    $cols  = explode(';', fgets($fileHandle));
    $query = sprintf(
        'INSERT INTO database_table (field1_name, field2_name) VALUES ("%s", "%s")',
        $cols[0], $cols[1]
    );

    mysql_query($query);
}

fclose($fileHandle);
mysql_close($db);
?>

And my txt file looks like this:

a;b
c;d
e;f
  • 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-26T21:32:37+00:00Added an answer on May 26, 2026 at 9:32 pm

    Did you try this?:

    LOAD DATA INFILE 'C:\\yourfile.txt'
    INTO TABLE yourtable
    FIELDS TERMINATED BY ';'
    LINES TERMINATED BY '\r\n'
    

    And then click the submit (go) button.

    EDIT: If you go the PHP route, try this:

    <?php
    $db = mysql_connect('localhost', 'mysql_user', 'mysql_password');
    if (!$db) {
        die('Could not connect: ' . mysql_error());
    }
    
    $fileHandle = fopen('yourfile.txt', 'rb');
    
    while (!feof($fileHandle)) {
        $cols  = explode(';', fgets($fileHandle));
        $query = sprintf(
            'INSERT INTO yourtable (column1, column2) VALUES ("%s", "%s")',
            $cols[0], $cols[1]
        );
    
        mysql_query($query);
    }
    
    fclose($fileHandle);
    mysql_close($db);
    

    It should work assuming each “row” is separated by a newline in the text file.

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

Sidebar

Related Questions

I am pretty new to both php and SQL. I have a login page
I am pretty new to PHP and MySQL and I just can't figure this
I'm pretty new to javascript and jquery, and have run into a problem that
I'm new to PHP and MySQL query construction. I have a processor for a
Well I am pretty new to both iphone and PHP development, and am trying
I am pretty new to both Dreamweaver and Coldfusion, and I am having a
Pretty new to MVC and the like. I have a class the looks like
I'm still pretty new to ObjC. I noticed that it's pretty standard everywhere to
I'm pretty new to PHP, but I decided to try and make a simple
I'm pretty new to databases and sql. I have a problem where I have

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.