I'm working on a project that involves a PHP script that calls an API and gets a JSON array. I then want to put this JSON array into a MySql database. The issue I am running into is that while the script executes without any errors or exceptions in the terminal, my database is not filling with any data.
I am running MySQL Workbench as my MySQL client and have created a schema called "team_data" into which I am attempting to input my JSON array. I have removed my API key for obvious reasons. Any ideas where I am going wrong here?
<?php
$con = mysql_connect("127.0.0.1","XXXXXX","XXXXXX") or die('Could not connect: ' . mysql_error());
mysql_select_db("test1", $con);
$json = file_get_contents('team_data.json');
$data = json_decode($json, true);
foreach($data as $row)
{
$game = $data['nfl_game_id'];
$team = $data['team'];
$opponent = $data['opponent'];
$totfirstdown = $data['totalfirstdown'];
$totyds = $data['totyds'];
$pyds = $data['pyds'];
$ryds = $data['ryds'];
$pen = $data['pen'];
$penyds = $data['penyds'];
$trnovr = $data['trnovr'];
$pt = $data['pt'];
$ptyds = $data['ptyds'];
$ptavg = $data['ptavg'];
$sql = "INSERT INTO Teams(nfl_game_id, team, opponent, totalfd, totyds, pyds, ryds, pen, penyds, trnovr, pt, ptyds, ptavg);
VALUES('$game', '$team', '$opponent', '$totfirstdown', '$totyds', '$pyds', '$ryds', '$pen', '$penyds', '$trnovr', '$pt', '$ptyds', '$ptavg')";
mysql_query($sql,$con);
}
?>