ameriblog Posted September 4, 2007 Share Posted September 4, 2007 I have the following code, trying to get content from a text file and inserting it into the database. Right now, for some reason, the code is only entering the first line from the .txt file and not the rest of the lines... <?php require ( "dbconnex.php" ); $lines = file('wv_scores.txt'); foreach ($lines as $line) { $team = $score = array(); $teamscore = explode(',', $line); foreach ($teamscore as $k=>$ts) { $x = strrpos($ts, ' '); $team[$k] = trim(substr($ts,0,$x)); $score[$k] = trim(substr($ts,$x)); } $games_rs = $conn->Execute ( "INSERT INTO wvhs_gm (team1_name, team1_score, team2_name, team2_score, game_year, team1, team2, game_extra, game_extra1, game_date, game_fixed) VALUES ('$team[0]', '$score[0]', '$team[1]', '$score[1]', 2007, 0, 0, 'NA', 'NA', '" . $_GET['date'] . "', 0)" ) or die ( $conn->ErrorMsg() ); $add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67912-help-with-getting-from-txt-file/ Share on other sites More sharing options...
wildteen88 Posted September 4, 2007 Share Posted September 4, 2007 How is wv_scrores.txt formatted? Post a few example lines from that file. From the looks of it should insert all lines into the database. Quote Link to comment https://forums.phpfreaks.com/topic/67912-help-with-getting-from-txt-file/#findComment-341402 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.