<?
$content=file("$form_data");
unset($content[1]);
$tabbed=implode("",preg_replace('%[ ]{2,}%s', "\t", $content));
preg_match_all("%(.*)\t(.*)\t(.*)\t(.*)%miU", $tabbed, $matches);
echo '<table border="1">
<tr>
<th>'.$matches[1][0].'</th>
<th>'.$matches[2][0].'</th>
<th>'.$matches[3][0].'</th>
</tr>';
for ($i=1; $i<count($matches[1]);$i++)
echo '<tr>
<td>'.$matches[1][$i].'</td>
<td>'.$matches[2][$i].'</td>
<td>'.$matches[3][$i].'</td>
</tr>';
echo '</table>';
?>
<?
$db=mysql_connect("localhost", "mflblin","1234gomfl");
mysql_select_db("mflblin_madden",$db);
//getting the teams's names
$team1=$matches[2][0];
$team2=$matches[3][0];
//querying their ids
echo $sql="SELECT
team_id, team_name
FROM
team
WHERE
team_name IN ('".$team1."', '".$team2."')";
$result=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_assoc($result))
$teams[]=$row;
//order them correct
if ($teams[0]['team_name']!=$matches[2][0])
list($teams[0], $teams[1])=array($teams[1], $teams[0]);
//insert game
print_r($teams);
echo $sql='INSERT INTO game
SET team1='.$teams[0]['team_id'].', team2='.$teams[1]['team_id'];
mysql_query($sql) or die(mysql_error());
//retrieve game_id
$game=mysql_insert_id();
//insert data
for ($i=1; $i<count($matches[2]); $i++)
$data[]=$matches[2][$i];
echo $sql='INSERT INTO result
(game_id, team_id, points, benchscoring, fieldgoals, fieldgoalp, threepointfg, threepointfgp, freethrows, freethrowp, rebounds, offrebounds, defrebounds, blocks, steals, assists, turnovers, fouls)
VALUES ('.$game.', '.$teams[0]['team_id'].', '.implode(', ', $data).')';
unset($data);
//test output
echo '<hr />'.$sql.'<p />';
mysql_query($sql) or die(mysql_error());
//the same for team2
for ($i=1; $i<count($matches[3]); $i++)
$data[]=$matches[3][$i];
echo $sql='INSERT INTO result
(game_id, team_id, points, benchscoring, fieldgoals, fieldgoalp, threepointfg, threepointfgp, freethrows, freethrowp, rebounds, offrebounds, defrebounds, blocks, steals, assists, turnovers, fouls)
VALUES ('.$game.', '.$teams[1]['team_id'].', '.implode(', ', $data).')';
//test output
echo $sql.'<hr />';
mysql_query($sql) or die(mysql_error());
//assuming $points1 are points of $teams[0]['team_id']
if ($points1 > $points2) //team1 won
{
mysql_query('UPDATE team SET wins=wins+1 WHERE team_id='.$teams[0]['team_id']);
mysql_query('UPDATE team SET losses=losses+1 WHERE team_id='.$teams[1]['team_id']);
}
else //team2 won
{
mysql_query('UPDATE team SET wins=wins+1 WHERE team_id='.$teams[1]['team_id']);
mysql_query('UPDATE team SET losses=losses+1 WHERE team_id='.$teams[0]['team_id']);
}
?>
You see the $points1 and 2 ?? Well I need them to mean this.
Points1=$teams[0] the number of points that team scored from the data submitted.
Points2=$teams[1] The Number of points that team scored from the data submitted