phirex Posted November 30, 2009 Share Posted November 30, 2009 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 More sharing options...
cags Posted November 30, 2009 Share Posted November 30, 2009 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' )"); } Link to comment https://forums.phpfreaks.com/topic/183441-how-to-insert-using-a-text-file/#findComment-968295 Share on other sites More sharing options...
Cardale Posted November 30, 2009 Share Posted November 30, 2009 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. Link to comment https://forums.phpfreaks.com/topic/183441-how-to-insert-using-a-text-file/#findComment-968299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.