Sunday, 25 August 2013

PHP & SQL: update record issue

PHP & SQL: update record issue

Having some difficulty pinpointing exactly what is wrong with this block
of code. I am expecting it to run through a loop a set number of times and
update some rows in the table tbl_games with some values received from the
form.
I have tried running the code in phpMyAdmin without variables, which works
fine (updates specified row). I assume the problem is something to do with
the string in $insert_q.
gamecount will always be an int<30, game_ID will be a unique primary key
integer value in tbl_games.
A little background: this code is part of a bigger project - which is
centered around football games. An admin adds games to tbl_games (coded
and finished), this current file now displays games to the admin which are
unplayed (scores for team1 and team2 are NULL) and gives them a space to
input scores for each team. This code takes those 2 scores, and the
game_ID and updates each row.
It's having no effect on the DB rows though. Please point me in the right
direction.
<?php
$lim=$_SESSION['gamecount'];
for ($i=1; $i<$lim; $i++) {
$game_ID = ${"_SESSION['game".$i."_ID']"};
$score_team_1 = ${"_REQUEST['".$i."_team1-score']"};
$score_team_2 = ${"_REQUEST['game".$i."_team2-score']"};
$insert_q = "UPDATE tbl_games SET team1_score = '$score_team_1',
team2_score = '$score_team_2' WHERE game_ID = '$game_ID';";
mysql_query($insert_q);
}
session_destroy();
?>

No comments:

Post a Comment