Jump to content

how to INSERT using a text file?


phirex

Recommended Posts

Hi

I'm probably the biggest newbie you have ever seen

i am trying to insert some data into my table

 

INSERT INTO `my_users` (`user_login`, `user_level`,`user_pass`, `user_karma`) VALUES

(*CHANGINGUSERNAME*, 'normal','password','5' );

 

what i want basically, is to have 'user_login' changed automatically by reading from a text file. each line has a username.

 

btw, there are 300 users, how do i make this run 300 times with the different users added (other values stay the same)

 

thanks alottt

 

Link to comment
https://forums.phpfreaks.com/topic/183441-how-to-insert-using-a-text-file/
Share on other sites

Get the contents of the file into an array. How you'd do that would depend on the exact format of the file, but from what you've described you probably want something like file. Then you can just do a foreach loop to insert all the files.

 

$users = file('path.txt');

foreach($users as $user) {
   mysql_query("INSERT INTO `my_users` (`user_login`, `user_level`,`user_pass`, `user_karma`) VALUES ('$user', 'normal','password','5' )");
}

Using a database would be faster than using a flat file then calling to the database, but if you must here is some good reading material http://php.net/manual/en/function.file-get-contents.php This should address your problem just short of me doing it for you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.