Jump to content

Recommended Posts

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() );





}
?>

Link to comment
https://forums.phpfreaks.com/topic/67912-help-with-getting-from-txt-file/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.