I have an if/else block of code below that is supposed to call a function with specific parameters, depending on the situation. The function updates specific values in the MySQL database. However, the database values are not being updated. What am I doing wrong?
The following is my code:
process.php
$success = false;
$homeScore = $_POST['home'];
$awayScore = $_POST['away'];
$homeTeamName = $_POST['homeTeam'];
$awayTeamName = $_POST['awayTeam'];
try {
$win = 0;
$loss = 0;
// HOME TEAM
if ($homeScore > $awayScore)
{
$win = 1; $loss = 0;
updateStandings($db7, $homeTeamName, $win, $loss);
$win = 0; $loss = 1;
updateStandings($db7, $awayTeamName, $win, $loss);
}
// AWAY TEAM
elseif ($awayScore > $homeScore)
{
$win = 1; $loss = 0;
updateStandings($db7, $awayTeamName, $win, $loss);
$win = 0; $loss = 1;
updateStandings($db7, $homeTeamName, $win, $loss);
}
$success = $_SERVER['HTTP_REFERER'];
}
catch (Exception $e)
{
$success="/error";
}
header("Location: " . $success);
function updateScore($db, $gameID, $home, $away)
{
$db -> updateScoreForGame($gameID, $home, $away);
}
function updateStandings($db, $teamName, $win, $loss)
{
$db -> updateLeagueStandings($teamName, $win, $loss);
}
updateLeagueStandings function
public function updateLeagueStandings($teamName, $win, $loss) {
try {
$sth = $this -> db -> prepare("UPDATE teams SET wins = wins + (:winsNum), losses = losses + (:lossesNum) WHERE Name = `:teamName`");
$sth->bindParam(':winsNum', $win, PDO::PARAM_INT);
$sth->bindParam(':lossesNum', $loss, PDO::PARAM_INT);
$sth->bindParam(':teamName', $teamName, PDO::PARAM_STR);
$sth -> execute();
} catch (Exception $e) {
header('Location: /error');
}
}
What's wrong here? Is the query wrong? I ran the query with substituted values in PHPMyAdmin and it worked fine, so it can't be the query.
if ($homeScore > $awayScore)...elseif ($awayScore > $homeScore)