Hello all,
I recently started php and mysql and am learning as I go. I have gotten a lot accomplished in a short time more out of necessity than anything. Anyway...I have ran into a portion of my script that isn't working correctly and I am at a loss. The entire page script I will post but all is working except for the UPDATE portion. I will highlight in red the areas....oh...and remember that I am kinda new at this so excuse any code etiquette thats ummm...questionable...suggestions are very much welcome.
<?php
include ("../../login/include/session.php");
?>
<?
$hteam = $_POST["home_team"];
$ateam = $_POST["away_team"];
$week_id = $_POST["week_id"];
$season_id = $_POST["season_id"];
$game_id = $_POST["game_id"];
$h_q1 = $_POST["h_q1"];
$h_q2 = $_POST["h_q2"];
$h_q3 = $_POST["h_q3"];
$h_q4 = $_POST["h_q4"];
$h_final = $_POST["h_final"];
$a_q1 = $_POST["a_q1"];
$a_q1 = $_POST["a_q2"];
$a_q1 = $_POST["a_q3"];
$a_q1 = $_POST["a_q4"];
$a_final = $_POST["a_final"];
$game_recap = $_POST["game_recap"];
if ($h_final > $a_final){
$winner=$hteam;
$loser = $ateam;
}
if ($a_final > $h_final){
$winner=$ateam;
$loser=$hteam;
}
//Check for game stat existance
$query = "SELECT game_status FROM game_scores WHERE game_id=$game_id";
$result = mysql_query($query) or die ("Problem checking game status");
$row=mysql_fetch_assoc($result);
if ($row["game_status"] != ""){
echo "Game data already exists. Contact Admin if this is an error.";
if ($row["game_status"] ==1){
echo "<br><a href=\"http://stadiumxbox.com\">Return to Home Page</a>";
echo "<br /><a href=\"http://stadiumxbox.com/leagues/ncaa/sta ... id\">Enter Individual Stats</a>";
}
}
else{
//Insert game score data
$query = "INSERT INTO game_scores VALUES ('NULL', '$season_id', '$week_id', '$game_id', '$home_team', '$away_team', '$h_q1', '$a_q1', '$h_q2', '$a_q2', '$h_q3', '$a_q3', '$h_q4', '$a_q4', '$h_final', '$a_final', 1, '$game_recap')";
mysql_query($query);
echo "Submission Complete <br><br>";
//Begin updating of wins and losses
$sql2 ="UPDATE ncaa_teams SET wins=wins+1 WHERE team_name=$winner";
mysql_query($sql2);
$sql3 ="UPDATE ncaa_teams SET losses=losses+1 WHERE team_name=$loser";
mysql_query($sql3);
?>
<br /><br /><a href="http://stadiumxbox.com">Return to Home Page</a><br />
<a href="http://stadiumxbox.com/leagues/ncaa/sta ... ;?>">Enter Individual Stats</a>
<?
}
?>
Help with an UPDATE script-SOLVED
Moderator: General Moderators
-
MountainXBGL
- Forum Newbie
- Posts: 3
- Joined: Sun Jun 29, 2008 10:23 am
Help with an UPDATE script-SOLVED
Last edited by MountainXBGL on Sun Jun 29, 2008 5:12 pm, edited 1 time in total.
-
MountainXBGL
- Forum Newbie
- Posts: 3
- Joined: Sun Jun 29, 2008 10:23 am
Re: Help with an UPDATE script
Also...
$sql2 ="UPDATE ncaa_teams SET wins=wins+1 WHERE team_name=$winner";
mysql_query($sql2);
$sql3 ="UPDATE ncaa_teams SET losses=losses+1 WHERE team_name=$loser";
mysql_query($sql3);
If I wanted to add a field to be updated....would I do it with:
....SET wins=wins+1, games_played=games_played+1 and same for the ....WHERE clause:
....WHERE team_name=$whatever AND season_id=$whatever
$sql2 ="UPDATE ncaa_teams SET wins=wins+1 WHERE team_name=$winner";
mysql_query($sql2);
$sql3 ="UPDATE ncaa_teams SET losses=losses+1 WHERE team_name=$loser";
mysql_query($sql3);
If I wanted to add a field to be updated....would I do it with:
....SET wins=wins+1, games_played=games_played+1 and same for the ....WHERE clause:
....WHERE team_name=$whatever AND season_id=$whatever
-
MountainXBGL
- Forum Newbie
- Posts: 3
- Joined: Sun Jun 29, 2008 10:23 am
Re: Help with an UPDATE script
Never mind....'$winner'...single quotes around the strings