Mr Chris Posted May 28, 2007 Share Posted May 28, 2007 Hi Guys, I'm in the process of putting together a script which you enter football results for, and depending on the results you put in this updates the league table accordingly below: http://www.slougheaz.org/football/tables/premiership.php Now here is where I enter my results to update this table: http://www.slougheaz.org/football/admin/premiership_results.php Now this system works: If: Team 1 score > Team 2 Team 1 score == Team 2 BUT Team 1 score < Team 2 (please feel free to try this yourself) An error is produced. Now I think there is something wrong with my code here } else if($team_1_score < $team_2_score) { $result = " update league_table set league ='p', team_losses=team_losses+1, team_gf=team_gf+'$team_1_score', team_ga=team_ga+'$team_2_score' where team_name='$team_1'"; $result2 = "update league_table set league ='p', team_wins=team_wins+1, team_gf=team_gf+'$team_2_score', team_ga=team_ga+'$team_1_score', team_points_total=team_points_total+3 where team_name='$team_2'"; And here's my full code as I was a bit vague before: <?php if(isset($_POST['formsubmit'])) { # insert the result into the table $team_1 = $_POST['team_1']; $team_1_score = $_POST['team_1_score']; $team_2 = $_POST['team_2']; $team_2_score = $_POST['team_2_score']; if(!mysql_query("insert into results (team_1, team_1_score, team_2, team_2_score, result) values ('$team_1', '$team_1_score', '$team_2', '$team_2_score', '')")) { echo 'oops '.mysql_error(); } # start calculations if($team_1_score > $team_2_score) { $result = " update league_table set league ='p', team_wins=team_wins+1, team_gf=team_gf+'$team_1_score', team_ga=team_ga+'$team_2_score', team_points_total=team_points_total+3 where team_name='$team_1'"; $result_2 = "update league_table set league ='p', team_losses=team_losses+1, team_gf=team_gf+'$team_2_score', team_ga=team_ga+'$team_1_score' where team_name='$team_2'"; } else if($team_1_score < $team_2_score) { $result = " update league_table set league ='p', team_losses=team_losses+1, team_gf=team_gf+'$team_1_score', team_ga=team_ga+'$team_2_score' where team_name='$team_1'"; $result2 = "update league_table set league ='p', team_wins=team_wins+1, team_gf=team_gf+'$team_2_score', team_ga=team_ga+'$team_1_score', team_points_total=team_points_total+3 where team_name='$team_2'"; } else if($team_1_score == $team_2_score) { $result = " update league_table set league ='p', team_draws=team_draws+1, team_gf=team_gf+'$team_1_score', team_ga=team_ga+'$team_2_score', team_points_total=team_points_total+1 where team_name='$team_1'"; $result_2 = " update league_table set league ='p', team_draws=team_draws+1, team_gf=team_gf+'$team_2_score', team_ga=team_ga+'$team_1_score', team_points_total=team_points_total+1 where team_name='$team_2'"; } if(!mysql_query($result)) { echo 'oops again '. mysql_error(); } if(!mysql_query($result_2)) { echo 'oops again 2 '. mysql_error(); } echo $team_1 . ' ' . $team_1_score .' VS '. $team_2 . ' ' . $team_2_score; } ?> <html> <head> <title>Teams</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="update" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <dl> <dt>Team 1</dt> <dl><select class="input" name="team_1" size="1" tabindex="1"> <option value="" selected>Teams</option> <?php $type_array=get_premiership_teams(); foreach ($type_array as $teams) { print("<option value=\"".$teams['team_name']."\">".$teams['team_name']."</option>\n"); } ?> </select> </dl> <dt>Team 1 score</dt> <dl><input name="team_1_score" type="text" size="5"> </dl> <dt>Team 2</dt> <dl><select class="input" name="team_2" size="1" tabindex="1"> <option value="" selected>Teams</option> <?php $type_array=get_premiership_teams(); foreach ($type_array as $teams) { print("<option value=\"".$teams['team_name']."\">".$teams['team_name']."</option>\n"); } ?> </select></dl> <dt>Team 2 score</dt> <dl><input name="team_2_score" type="text" size="5"> <input type="hidden" name="formsubmit"> </dl> </dl> <input type="submit" name="submit" label="submit"> </form> </body> </html> Anything wrong with my queries or code? Thanks Chris Quote Link to comment https://forums.phpfreaks.com/topic/53263-solved-league-table-script-help/ Share on other sites More sharing options...
MadTechie Posted May 28, 2007 Share Posted May 28, 2007 Please use code tags and An error is produced. isn't very useful! Quote Link to comment https://forums.phpfreaks.com/topic/53263-solved-league-table-script-help/#findComment-263202 Share on other sites More sharing options...
Mr Chris Posted May 28, 2007 Author Share Posted May 28, 2007 Sorry, should have been more detailed: Query was empty Thanks Chris Quote Link to comment https://forums.phpfreaks.com/topic/53263-solved-league-table-script-help/#findComment-263427 Share on other sites More sharing options...
Barand Posted May 28, 2007 Share Posted May 28, 2007 You used $result2 instead of $result_2 Quote Link to comment https://forums.phpfreaks.com/topic/53263-solved-league-table-script-help/#findComment-263495 Share on other sites More sharing options...
Mr Chris Posted May 28, 2007 Author Share Posted May 28, 2007 I knew it was something simple!!! Thanks for the proofread! Quote Link to comment https://forums.phpfreaks.com/topic/53263-solved-league-table-script-help/#findComment-263499 Share on other sites More sharing options...
Barand Posted May 28, 2007 Share Posted May 28, 2007 Nothing you couldn't have done. Quote Link to comment https://forums.phpfreaks.com/topic/53263-solved-league-table-script-help/#findComment-263505 Share on other sites More sharing options...
Mr Chris Posted May 28, 2007 Author Share Posted May 28, 2007 True, I did proofread, but sometimes the most obvious thing is the least obvious if you have been looking code for hours... :-) Quote Link to comment https://forums.phpfreaks.com/topic/53263-solved-league-table-script-help/#findComment-263511 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.