Hello, might be a fairly simple (hopefully) solution but...
I've been looking for answers to this problem but I haven't been able to come up with something that works in my situation.
Basically what I want to do is have 4 pages linked in this order and function:
Page 1: Select two teams.
Page 2: Call up those two teams and their player rosters and stats. Input the desired values and go to;
Page 3: Call up the two teams' season stats. Input the desired values and go to;
Page 4: Call up the two teams' goalie rosters. Input the desired values.
Keep in mind that it is updating multiple records each time (at least 2, and in the case of the player rosters, about 40). I can get them all to work independently, but I do not know how to link them all together.
The problem is that when I input and submit the player stats it seems to skip the part where it's building the proper query, and skips right ahead to the next page. A similar thing happens when you also try to submit from the team page.
Basically on page one you use an option list and pick two teams and store them as $Team1 and $Team2 to be used in the second form (<form method="POST" action="submitplayerstats.php"> )
The second page can get the two values just fine (I.e. Toronto and Boston) and display the relevant information.
Here's the player submit page, which would be the first page to submit actual stats.
<?
if (!$HTTP_POST_VARS[submit]) {
$db=mysql_connect ("localhost", *) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xshocke_players",$db);
$query="SELECT * FROM players WHERE Team='$_POST[Team1]' or Team='$_POST[Team2]' ORDER BY Team";
$result=mysql_query($query);
echo "query is:";
echo $query;
echo "<br>";
echo "result is:";
echo $result;
echo "<br>";
echo "<center><h1> Game Submission Testing </h1></center>";
if (mysql_num_rows($result) !=0) {
echo "<table width=75% align=center>\n";
echo "<form method=POST action=submitstatsteamxs.php>";
echo "<input type=hidden name=Team1 value='$_POST[Team1]'>\n";
echo "<input type=hidden name=Team2 value='$_POST[Team2]'>\n";
echo "<tr><td>Team</td><td>Name</td><td>Position</td><td>Goals</td><td>Assists</td><td>SHG</td><td>PPG</td><td>PIM</td></tr>\n";
while ($r = mysql_fetch_array($result)) {
$id = $r["id"];
$Team = $r["Team"];
$Name = $r["Name"];
$Position = $r["Position"];
$GP = $r["GP"];
$Goals = $r["Goals"];
$Assists = $r["Assists"];
$SHG = $r["SHG"];
$PPG = $r["PPG"];
$PIM = $r["PIM"];
echo "<input type=hidden name=yapp[$id] value='$id'>\n";
echo "<tr><td><input readonly type=text name=yapp[$id][Team] value='$Team' size=20></td>\n";
echo "<td><input readonly type=text name=yapp[$id][Name] value='$Name' size=20></td>\n";
echo "<td><input type=text name=yapp[$id][Position] value='$Position' size=2></td>\n";
echo "<input type=hidden name=yapp[$id][GP] value='1' size=2>\n";
echo "<td><input type=text name=yapp[$id][Goals] value='0' size=2></td>\n";
echo "<td><input type=text name=yapp[$id][Assists] value='0' size=2></td>\n";
echo "<td><input type=text name=yapp[$id][SHG] value='0' size=2></td>\n";
echo "<td><input type=text name=yapp[$id][PPG] value='0' size=2></td>\n";
echo "<td><input type=text name=yapp[$id][PIM] value='0' size=2></td></tr>\n";
}
echo "<tr><td align=center colspan=8><input type=submit name=submit1 value=submit1></td></tr>\n";
echo "</form>";
echo "</table>";
} else {
echo "Couldn't fetch info from the db...";
}
} else {
$db=mysql_connect ("localhost", *) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xshocke_players",$db);
while (list ($key2) = each ($HTTP_POST_VARS[yapp])) {
$query="UPDATE players SET ";
foreach ($HTTP_POST_VARS[yapp][$key2] as $key3 => $value3) {
if (!empty($value3)) {
//see if the $key3 variable is the correct column then
//change the code to add the current value and the input value
if (($key3=="GP")||($key3=="Goals")||($key3=="Assists")||($key3=="PPG")||($key3=="SHG")||($key3=="PIM")){
$query.="$key3=$key3+$value3 ,";
$query.="Points = Goals + Assists, ";
}
else{
$query.="$key3='$value3', ";
}
}
}
$query=substr($query, 0,-2);
$query.=" WHERE id=$key2";
echo "$query <br>";
$result=mysql_query($query) or die (mysql_error());
}
}
?>
When I hit submit from that page it gives me this query:
UPDATE teams SET Team='Test', Name='Holzinger B', Position='C', GP=GP+1 ,Points = (Wins * 2) + OTL + Ties, ShootingPct = round(GF / Shots,3), GAA = round(GA / GP,2), GFA = round(GF / GP,2), ShotsAvg = round(Shots / GP,2), HitsAvg = round(Hits / GP,2), PIMAvg = round(PIM / GP,2) WHERE id=33
and this error: 'Unknown column 'Name' in 'field list'
Obviously this error is because it's using the query builder from the next page, the team stats page, instead of using the one that is already on its own page. How come it is skipping ahead to the next page instead of doing what it should be on its own? I think it may have something to do with my IFs, but I'm not sure. Anyway, here is the next page of code:
<?
if (!$HTTP_POST_VARS[submit1]) {
$db=mysql_connect ("localhost", *) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xshocke_players",$db);
$query1="SELECT * FROM teams WHERE Team='$_POST[Team1]' or Team='$_POST[Team2]' ORDER BY Team";
$result1=mysql_query($query1);
echo "query1 is:";
echo $query1;
echo "<br>";
echo "result1 is:";
echo $result1;
echo "<br>";
echo "<center><h1> Team Stats Submission </h1></center>";
if (mysql_num_rows($result1) !=0) {
echo "<table width=90% align=center>\n";
echo "<form method=POST action=submitstatsgoaliexs.php>\n";
echo "<input type=hidden name=Team1 value='$_POST[Team1]'>\n";
echo "<input type=hidden name=Team2 value='$_POST[Team2]'>\n";
echo "<tr><td>Team</td><td>W</td><td>L</td><td>T</td><td>OTL</td><td>GF</td><td>GA</td><td>Shots</td><td>Hits</td><td>PIM</td><td>PPG</td><td>PPA</td><td>PK</td><td>PKT</td></tr>\n";
while ($r = mysql_fetch_array($result1)) {
*I HAD TO REDUCE THE MSG LENGTH AND THIS CONTAINED SOME REPETITIVE STUFF THAT I KNOW IS FINE, SEE THE FIRST FILE FOR WHAT IT BASICALLY LOOKS LIKE, JUST WITH DIFF VARS*
}
echo "<tr><td align=center colspan=15><input type=submit name=submit2 value=submit2></td></tr>\n";
echo "</form>";
echo "</table>";
} else {
echo "Couldn't fetch info from the db...";
}
} else {
$db=mysql_connect ("localhost", *) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xshocke_players",$db);
while (list ($key1) = each ($HTTP_POST_VARS[yapp])) {
$query1="UPDATE teams SET ";
foreach ($HTTP_POST_VARS[yapp][$key1] as $key2 => $value2) {
if (!empty($value2)) {
//see if the $key1 variable is the correct column then
//change the code to add the current value and the input value
if (($key2=="GP")||($key2=="Wins")||($key2=="Losses")||($key2=="Ties")||($key2=="OTL")||($key2=="GF")||($key2=="GA")||($key2=="Shots")||($key2=="Hits")||($key2=="PIM")||($key2=="PPScored")||($key2=="PPAttempts")||($key2=="PKKilled")||($key2=="PKTotal")){
$query1.="$key2=$key2+$value2 ,";
$query1.="Points = (Wins * 2) + OTL + Ties, ";
$query1.="ShootingPct = round(GF / Shots,3), ";
$query1.="GAA = round(GA / GP,2), ";
$query1.="GFA = round(GF / GP,2), ";
$query1.="ShotsAvg = round(Shots / GP,2), ";
$query1.="HitsAvg = round(Hits / GP,2), ";
$query1.="PIMAvg = round(PIM / GP,2), ";
}
else{
$query1.="$key2='$value2', ";
}
}
}
$query1=substr($query1, 0,-2);
$query1.=" WHERE id=$key1";
echo "$query1 <br>";
$result1=mysql_query($query1) or die (mysql_error());
}
}
?>
If you guys could give me any help, I'd be incredibly happy. Thanks in any case.