bgh10788
08-13-2007, 04:46 PM
I'm working on creating a gaming ladder for a tournament I'm in charge of. I'm having some trouble with getting the post values from a form after it has been submitted. Here is the link to the page...
gulfcoastcommandos.freehostia.com/changeposition.php
Everything comes up fine, but as soon as you try to submit it, all the positions in the database are set to 0 (zero). I believe I have narrowed it down to the $newpos=$_POST['$teamname'] line because in on the next page, it displays "Team Name: ... Position: "with nothing following position(no number, no text).
Here is the code for the place where the admin can make the changes to the team position. Everything on this page displays and works appropriately (except the POST passing of values). You'll have to trust me on this because as soon as someone here goes and tries to change them, this page no longer works since all team positions are 0.
<?php
include("include/logincheck.php");
include("include/header.php");
include("include/connect.php");
include("include/admincheck.php");
?>
<div align="center" class="style7">
<br><br>
Adjust the order of the teams by selecting a new number in the box.<br><br>
<form action="processchangeposition.php" method="POST">
<table width="40%">
<?php
//get the maximum position from the database
$query="SELECT position FROM team";
$result=mysql_query($query)
or die("Database is unreachable. Contact an administrator or try again in a few minutes.");
while ($row=mysql_fetch_assoc($result))
{
extract($row);
if ($position>$maxpos)
{
$maxpos=$position;
}
}
//get all the team names and positions
$query="SELECT name, position FROM team ORDER BY position";
$result=mysql_query($query)
or die("Error connecting to database");
//cycle through the array of teams and make an option to change the position of each team based on the $maxpos variable
while ($row=mysql_fetch_assoc($result))
{
extract($row);
//create different drop-down select for each team
echo "<tr>
<td class='style7'>$name</td>
<td class='style7'><select name='$name'>";
for ($a=1;$a<=$maxpos;$a++)
{
if ($position==$a)
{
echo "<option value='$a' selected='selected'>$a";
}
else
{
echo "<option value='$a'>$a";
}
}
echo "</select></td></tr>";
}
?>
<tr>
<td class="style7" colspan="2" align="center"><input type="submit" value="Submit Changes"></td>
</tr>
</table>
</form>
</div>
<?php
include("include/footer.php");
?>
Here is the code for what happens to process the change
<?php
include("include/logincheck.php");
include("include/header.php");
include("include/connect.php");
include("include/admincheck.php");
?>
<div align="center" class="style7">
<?php
//cycle through all the teams in the database
$query="SELECT name FROM team ORDER BY position";
$result=mysql_query($query)
or die("Error connecting to database");
while ($row=mysql_fetch_assoc($result))
{
//get the team name from the database
$teamname=$row['name'];
//get the position from the POST variable - NOT WORKING!!!
$pos=$_POST['$teamname'];
echo "Name: $teamname Position: $pos <br>";
//update the database for each team
$query1="UPDATE team SET position='$pos' WHERE name='$teamname'";
$result1=mysql_query($query1)
or die("Error connecting to database");
}
?>
<br><br>
Team positions changed successfully.
</div>
<?php
include("include/footer.php");
?>
Thank you in advance for your help.
gulfcoastcommandos.freehostia.com/changeposition.php
Everything comes up fine, but as soon as you try to submit it, all the positions in the database are set to 0 (zero). I believe I have narrowed it down to the $newpos=$_POST['$teamname'] line because in on the next page, it displays "Team Name: ... Position: "with nothing following position(no number, no text).
Here is the code for the place where the admin can make the changes to the team position. Everything on this page displays and works appropriately (except the POST passing of values). You'll have to trust me on this because as soon as someone here goes and tries to change them, this page no longer works since all team positions are 0.
<?php
include("include/logincheck.php");
include("include/header.php");
include("include/connect.php");
include("include/admincheck.php");
?>
<div align="center" class="style7">
<br><br>
Adjust the order of the teams by selecting a new number in the box.<br><br>
<form action="processchangeposition.php" method="POST">
<table width="40%">
<?php
//get the maximum position from the database
$query="SELECT position FROM team";
$result=mysql_query($query)
or die("Database is unreachable. Contact an administrator or try again in a few minutes.");
while ($row=mysql_fetch_assoc($result))
{
extract($row);
if ($position>$maxpos)
{
$maxpos=$position;
}
}
//get all the team names and positions
$query="SELECT name, position FROM team ORDER BY position";
$result=mysql_query($query)
or die("Error connecting to database");
//cycle through the array of teams and make an option to change the position of each team based on the $maxpos variable
while ($row=mysql_fetch_assoc($result))
{
extract($row);
//create different drop-down select for each team
echo "<tr>
<td class='style7'>$name</td>
<td class='style7'><select name='$name'>";
for ($a=1;$a<=$maxpos;$a++)
{
if ($position==$a)
{
echo "<option value='$a' selected='selected'>$a";
}
else
{
echo "<option value='$a'>$a";
}
}
echo "</select></td></tr>";
}
?>
<tr>
<td class="style7" colspan="2" align="center"><input type="submit" value="Submit Changes"></td>
</tr>
</table>
</form>
</div>
<?php
include("include/footer.php");
?>
Here is the code for what happens to process the change
<?php
include("include/logincheck.php");
include("include/header.php");
include("include/connect.php");
include("include/admincheck.php");
?>
<div align="center" class="style7">
<?php
//cycle through all the teams in the database
$query="SELECT name FROM team ORDER BY position";
$result=mysql_query($query)
or die("Error connecting to database");
while ($row=mysql_fetch_assoc($result))
{
//get the team name from the database
$teamname=$row['name'];
//get the position from the POST variable - NOT WORKING!!!
$pos=$_POST['$teamname'];
echo "Name: $teamname Position: $pos <br>";
//update the database for each team
$query1="UPDATE team SET position='$pos' WHERE name='$teamname'";
$result1=mysql_query($query1)
or die("Error connecting to database");
}
?>
<br><br>
Team positions changed successfully.
</div>
<?php
include("include/footer.php");
?>
Thank you in advance for your help.