Ok, i've changed the code (see below) but i'm not getting any output of any kind. Any idea's what is causing the problem? Using existing sql data is brand new to me, so I don't really have any which part is causing the problem.
In the original code, the if/switch statements all worked fine. I believe it is the assignment of the variables that is the problem.
<?php
error_reporting(E_ALL);
//SCORE ADDITION CODE.
//Connect & Select.
$con = mysql_connect("localhost","u08105199","11011100");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("u08105199", $con);
//Declare variables.
$leagueName = mysql_real_escape_string($_POST["leagueName"]);
$player1 = mysql_real_escape_string($_POST["playerOneName"]);
$player2 = mysql_real_escape_string($_POST["playerTwoName"]);
$result = mysql_real_escape_string($_POST["result"]);
$comments = mysql_real_escape_string($_POST["comments"]);
//Get timestamp variable.
$timestamp=date("d/m/Y");
//Pull from sql table.
$p1result = mysql_query("SELECT * FROM $leagueName WHERE PlayerName = $player1") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
$p2result = mysql_query("SELECT * FROM $leagueName WHERE PlayerName = $player2") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
//Assign p1 variables.
$row=mysql_fetch_array($p1result));
$player1gp=$row["GamesPlayed"];
$player1wins=$row["Wins"];
$player1losses=$row["Losses"];
$player1draws=$row["Draws"];
$player1points=$row["Points"];
//Assign p2 variables.
$row2=mysql_fetch_array($p2result));
$player2gp=$row2["GamesPlayed"];
$player2wins=$row2["Wins"];
$player2losses=$row2["Losses"];
$player2draws=$row2["Draws"];
$player2points=$row2["Points"];
var_dump($player1gp,$player1wins,$player1losses,$player1draws,$player1points,$player2gp,$player2wins,$player2losses,$player2draws,$player2points);
//Do calculation code.
$player1winpercent = ($player1gp/$player1wins) * 100;
$player2winpercent = ($player2gp/$player2wins) * 100;
if ($player1winpercent > $player2winpercent)
{
$percentDiff = $player1winpercent - $player2winpercent;
if ($percentDiff < 10)
{
$player1pts = 18;
$player2pts = 18;
$player1minus = -11;
$player2minus = -11;
}
else if ($percentDiff < 20)
{
$player1pts = 17;
$player2pts = 19;
$player1minus = -12;
$player2minus = -10;
}
else if ($percentDiff < 30)
{
$player1pts = 16;
$player2pts = 20;
$player1minus = -13;
$player2minus = -9;
}
else if ($percentDiff < 40)
{
$player1pts = 15;
$player2pts = 21;
$player1minus = -14;
$player2minus = -8;
}
else if ($percentDiff < 50)
{
$player1pts = 14;
$player2pts = 22;
$player1minus = -15;
$player2minus = -7;
}
else if ($percentDiff < 60)
{
$player1pts = 13;
$player2pts = 23;
$player1minus = -16;
$player2minus = -6;
}
else if ($percentDiff < 70)
{
$player1pts = 12;
$player2pts = 24;
$player1minus = -17;
$player2minus = -5;
}
else if ($percentDiff < 80)
{
$player1pts = 11;
$player2pts = 25;
$player1minus = -18;
$player2minus = -4;
}
else if ($percentDiff < 90)
{
$player1pts = 10;
$player2pts = 26;
$player1minus = -19;
$player2minus = -3;
}
else
{
$player1pts = 9;
$player2pts = 27;
$player1minus = -20;
$player2minus = -2;
}
}
else
{
$percentDiff = $player2winpercent - $player1winpercent;
$percentDiff = $player1winpercent - $player2winpercent;
if ($percentDiff < 10)
{
$player2pts = 18;
$player1pts = 18;
$player1minus = -11;
$player2minus = -11;
}
else if ($percentDiff < 20)
{
$player2pts = 17;
$player1pts = 19;
$player1minus = -10;
$player2minus = -12;
}
else if ($percentDiff < 30)
{
$player2pts = 16;
$player1pts = 20;
$player1minus = -9;
$player2minus = -13;
}
else if ($percentDiff < 40)
{
$player2pts = 15;
$player1pts = 21;
$player1minus = -8;
$player2minus = -14;
}
else if ($percentDiff < 50)
{
$player2pts = 14;
$player1pts = 22;
$player1minus = -7;
$player2minus = -15;
}
else if ($percentDiff < 60)
{
$player2pts = 13;
$player1pts = 23;
$player1minus = -6;
$player2minus = -16;
}
else if ($percentDiff < 70)
{
$player2pts = 12;
$player1pts = 24;
$player1minus = -5;
$player2minus = -17;
}
else if ($percentDiff < 80)
{
$player2pts = 11;
$player1pts = 25;
$player1minus = -4;
$player2minus = -18;
}
else if ($percentDiff < 90)
{
$player2pts = 10;
$player1pts = 26;
$player1minus = -3;
$player2minus = -19;
}
else
{
$player2pts = 9;
$player1pts = 27;
$player1minus = -2;
$player2minus = -20;
}
}
//Find winner.
switch ($result)
{
case "defeated":
mysql_query("UPDATE $leagueName SET GamesPlayed=GamesPlayed+1, Wins=Wins+1, Points=Points+$player1pts
WHERE PlayerName = '$player1' LIMIT 1") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
mysql_query("UPDATE $leagueName SET GamesPlayed=GamesPlayed+1, Losses=Losses+1, Points=Points+$player2minus
WHERE PlayerName = '$player2' LIMIT 1") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
echo ("$timestamp - $player1 $result $player2 in the league - $leagueName.");
break;
case "lost to":
mysql_query("UPDATE $leagueName SET GamesPlayed=GamesPlayed+1, Wins=Wins+1, Points=Points+$player2pts
WHERE PlayerName = '$player2' LIMIT 1") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
mysql_query("UPDATE $leagueName SET GamesPlayed=GamesPlayed+1, Losses=Losses+1, Points=Points+$player1minus
WHERE PlayerName = '$player1' LIMIT 1") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
echo ("$timestamp - $player1 $result $player2 in the league - $leagueName.");
break;
case "drew with":
mysql_query("UPDATE $leagueName SET GamesPlayed=GamesPlayed+1, Draws=Draws+1, Points=Points+10
WHERE PlayerName = '$player1' LIMIT 1") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
mysql_query("UPDATE $leagueName SET GamesPlayed=GamesPlayed+1, Draws=Draws+1, Points=Points+10
WHERE PlayerName = '$player2' LIMIT 1") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
echo ("$timestamp - $player1 $result $player2 in the league - $leagueName.");
break;
default:
echo "No result selected!";
}
//RESULT LOG CODE.
// Create result string.
$addresult = "$timestamp - $player1 $result $player2 in the $leagueName league.";
// Store results.
mysql_query("INSERT INTO Result_Log (League, Result, Comment, `Timestamp`)
VALUES ('$leagueName', '$addresult', '$comments', '$timestamp')") or trigger_error('Query failed: ' . conn->error, E_USER_ERROR);
mysql_close($con);
?>
<html>
<br />
<br />
<a href="http://student.dc.lincoln.ac.uk/~u08105199/admin.php">Click here</a> to go back to the homepage!
</html>