papaface Posted June 6, 2007 Share Posted June 6, 2007 Hello, How would I run a query for each line in a text file? I have this so far but it doesnt work: <?php mysql_connect("localhost","xxx","xxx") or die (mysql_error()); mysql_select_db("xxxx") or die (mysql_error()); $filename = "file.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); foreach($contents as $line_num => $line) { mysql_query("insert into cats (category) values ('{$line}')") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54373-solved-run-a-query-for-each-line/ Share on other sites More sharing options...
papaface Posted June 6, 2007 Author Share Posted June 6, 2007 Got it working. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/54373-solved-run-a-query-for-each-line/#findComment-268883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.