Hi all,
New to php and would be grateful for the help. I am making a league site up as a project and this is my reporting code. I can update the player fine but the WHERE statement to select all other players and update their ranks is not working correctly it is updating all other ranks to 1 not their rank + 1, maybe it's just a syntax thing that I have wrong. If some one could point me in the right direction it would be great. TY.
$userid = mysql_real_escape_string($userid);
$password = mysql_real_escape_string($password);
$opponent = mysql_real_escape_string($opponent);
$rank1recieve = mysql_query("SELECT rank FROM users WHERE playername='$userid'");
$rank2recieve = mysql_query("SELECT rank FROM users WHERE playername='$opponent'");
$rank1 = mysql_fetch_array($rank1recieve);
$rank2 = mysql_fetch_array($rank2recieve);
$rankdifference = ceil(($rank1['rank'] - $rank2['rank']) 0.5); // distance to move up in rank//
if ($rec = mysql_fetch_array(mysql_query("SELECT FROM users WHERE playername='$userid' AND password = '$password'")))
{
if (($rec['playername'] == $userid) && ($rec['password'] == $password)) // check password//
{
if ($rank1['rank'] > $rank2['rank'])
{
$newrank = $rank1['rank'] - $rankdifference;
$rankupper = $rank1['rank'];
$updateallotherranks = mysql_query("SELECT rank FROM users WHERE rank >= '$newrank' AND rank < '$rankupper'");
while ($updatealllink1 = mysql_fetch_array($updateallotherranks))
{
$otherplayeroldrank = $updatealllink1['rank'];
$newotherplayerrank = $otherplayernewrank + 1;
$updateotherplayerranks = mysql_query("UPDATE users SET rank = '$newotherplayerrank' WHERE rank = '$otherplayeroldrank'");
}
$rankupdate = mysql_query("UPDATE users SET rank='$newrank' WHERE playername='$userid'");
echo "<br>";
echo "newrank " . $newrank;
echo "<br>";
echo "players rank " . $rank1['rank'];
echo "<br>";
echo "opponents rank " . $rank2['rank'];
echo "<br>";
echo " difference in thier rank " . $rankdifference;
echo "<p class=data> <center>Match Reported<br><br>";
}
}
}
else
{
echo "<font face='Verdana' size='2' color=red>Wrong Password or Username<br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
}