<?PHP
$db = mysql_connect("a", "a", "a") or die("Connection Failure to Database");
mysql_select_db("a", $db) or die ("Connection Failure to Database");
if(isset($_POST['pet']))
{
//Enter dog into show
$sql = 'INSERT INTO `pet`.`show` (`petname`, `totalstats`) VALUES (\'' . $_POST['pet'] . '\', \'' . $_POST['total'] . '\')';
mysql_query($sql);
echo $_POST['pet'] . ' Entered show.';
}
//SHOW USERS DOG(S)
$sql = "SELECT petname, totalstats FROM pets WHERE owerid ='" . $_SESSION['id'] . "'";
$result = mysql_query($sql);
$check = @mysql_num_rows($result);
if($check == 0)
{
echo 'You have no animals.';
}
else
{
echo '<table border="1"><tr><td><b>Pet Name</b></td><td><b>Total Stats</b></td><td><b>Enter Comp</b></td></tr>';
while($row = @mysql_fetch_array($result))
{
echo '<tr>
<td>' . $row['petname'] . '</td><td>' . $row['totalstats'] . '</td><td>' . checkentered($row['petname'],$row['totalstats']) . '</td></tr>';
}
}
echo '</table><br>';
//CHECK IF PET IS IN THE SHOW
function checkentered($petname, $total)
{
$sql = "SELECT petname FROM show WHERE petname = '$petname'";
$result = mysql_query($sql);
$check = @mysql_num_rows($result);
if($check == 0)
{
$r = '<form name="enterdog" method="post" action=""><input type="hidden" name="total" value="' . $total . '"><input type="hidden" name="pet" value="' . $petname . '"><input type="submit" value="Enter"></form>';
}
else
{
$r = "This dog has already been entered";
}
return $r;
}
//SHOW SYSTEM
$sql = "SELECT * FROM `show` ORDER BY totalstats DESC";
$result = mysql_query($sql);
$check = @mysql_num_rows($result);
if($check == 0)
{
echo 'The show has no contests.';
}
else
{
echo '<table border="1"><tr><td><b>Postion</b></td><td><b>Pet Name</b></td><td><b>Total Stats</b></td></tr>';
while($row = mysql_fetch_array($result))
{
$i++;
echo '<tr>
<td>' . $i . '</td>
<td>' . $row['petname'] . '</td>
<td>' . $row['totalstats'] . '</td>
</tr>';
}
}
echo '</table>';
?>