Top
Home

##############################################################################
##############################################################################
######################### Install.php ######################################

<?php
$con=mysqli_connect("HOSTNAME","USERNAME","PASSWORD","DATABASE");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} $sql="
CREATE TABLE `Contestants` (
`id` int(11) NOT NULL auto_increment,
`Team` varchar(250) NULL DEFAULT NULL,
`Question` varchar(250) NULL DEFAULT NULL,
`Time` varchar(250) NULL DEFAULT NULL,
`ip` varchar(250) NULL DEFAULT NULL,
`todae` varchar(250) NULL DEFAULT NULL,
PRIMARY KEY  (`id`)
)
";
if (mysqli_query($con,$sql))
{
echo "<Center>Contestants created successfully! Yee Haa!!<br><br> <img src=\"http://www.mooseloose.com/images/0002.jpg\">";
}
else
{
echo "Error creating table: " . mysqli_error($con);
}
?>

##############################################################################
##############################################################################
############################ Install.php ##################################

<?php
$con=mysqli_connect("localhost","USERNAME","PASSWORD","DATABASE");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} $sql="
CREATE TABLE `Scores` (
`id` int(11) NOT NULL auto_increment,
`Team` varchar(250) NULL DEFAULT NULL,
`Points` varchar(250) NULL DEFAULT NULL,
`ip` varchar(250) NULL DEFAULT NULL,
`todae` varchar(250) NULL DEFAULT NULL,
PRIMARY KEY  (`id`)
)
";
if (mysqli_query($con,$sql))
{
echo "<Center>Scores created successfully! Yee Haa!!<br><br> <img src=\"http://www.mooseloose.com/images/0002.jpg\">";
}
else
{
echo "Error creating table: " . mysqli_error($con);
}


?>

##############################################################################
##############################################################################
########################## Game00.php ###################################

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE></TITLE>
</HEAD>
<BODY>
<form name="FearDearg" action="Game01.php" method="post">
<table border="0" cellpadding="0" cellspacing="2" width="300">
<tr>
<td align=right>Team: </td>
<td>
<SELECT NAME="Team">
<OPTION VALUE=""></OPTION>
<OPTION VALUE="Alabama">Alabama</OPTION>
<OPTION VALUE="Alaska">Alaska</OPTION>
<OPTION VALUE="Arizona">Arizona</OPTION>
<OPTION VALUE="Arkansas">Arkansas</OPTION>
<OPTION VALUE="California">California</OPTION>
<OPTION VALUE="Colorado">Colorado</OPTION>
<OPTION VALUE="Connecticut">Connecticut</OPTION>
<OPTION VALUE="Delaware">Delaware</OPTION>
<OPTION VALUE="Florida">Florida</OPTION>
<OPTION VALUE="Georgia">Georgia</OPTION>
<OPTION VALUE="Hawaii">Hawaii</OPTION>
<OPTION VALUE="Idaho">Idaho</OPTION>
<OPTION VALUE="Illinois">Illinois</OPTION>
<OPTION VALUE="Indiana">Indiana</OPTION>
<OPTION VALUE="Iowa">Iowa</OPTION>
<OPTION VALUE="Kansas">Kansas</OPTION>
<OPTION VALUE="Kentucky">Kentucky</OPTION>
<OPTION VALUE="Louisiana">Louisiana</OPTION>
<OPTION VALUE="Maine">Maine</OPTION>
<OPTION VALUE="Maryland">Maryland</OPTION>
<OPTION VALUE="Massachusetts">Massachusetts</OPTION>
<OPTION VALUE="Michigan">Michigan</OPTION>
<OPTION VALUE="Minnesota">Minnesota</OPTION>
<OPTION VALUE="Mississippi">Mississippi</OPTION>
<OPTION VALUE="Missouri">Missouri</OPTION>
<OPTION VALUE="Montana">Montana</OPTION>
<OPTION VALUE="Nebraska">Nebraska</OPTION>
<OPTION VALUE="Nevada">Nevada</OPTION>
<OPTION VALUE="New Hampshire">New Hampshire</OPTION>
<OPTION VALUE="New Jersey">New Jersey</OPTION>
<OPTION VALUE="New Mexico">New Mexico</OPTION>
<OPTION VALUE="New York">New York</OPTION>
<OPTION VALUE="North Carolina">North Carolina</OPTION>
<OPTION VALUE="North Dakota">North Dakota</OPTION>
<OPTION VALUE="Ohio">Ohio</OPTION>
<OPTION VALUE="Oklahoma">Oklahoma</OPTION>
<OPTION VALUE="Oregon">Oregon</OPTION>
<OPTION VALUE="Pennsylvania">Pennsylvania</OPTION>
<OPTION VALUE="Rhode Island">Rhode Island</OPTION>
<OPTION VALUE="South Carolina">South Carolina</OPTION>
<OPTION VALUE="South Dakota">South Dakota</OPTION>
<OPTION VALUE="Tennessee">Tennessee</OPTION>
<OPTION VALUE="Texas">Texas</OPTION>
<OPTION VALUE="Utah">Utah</OPTION>
<OPTION VALUE="Vermont">Vermont</OPTION>
<OPTION VALUE="Virginia">Virginia</OPTION>
<OPTION VALUE="Washington">Washington</OPTION>
<OPTION VALUE="West Virginia">West Virginia</OPTION>
<OPTION VALUE="Wisconsin">Wisconsin</OPTION>
<OPTION VALUE="Wyoming">Wyoming</OPTION>
</SELECT>
</td>
<td align=right>Contestant: </td>
<td><input type="text" name="Contestant" size="24" value=""> </td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" Value="Register Team"></td>
</tr>
</table>
</form>
</BODY>
</HTML>

##############################################################################
##############################################################################
########################## Game01.php ###################################

<html>
<head>

<?php
$Team=$_POST['Team'];
$Contestant=$_POST['Contestant'];
Echo "<h1>";
Echo $Team;
Echo " | ";
Echo $Contestant;
Echo "</h1>";
?>


<script>
function showUser(str) {
 if (str=="") {
   document.getElementById("MooseLoose").innerHTML="";
   return;
 }
 if (window.XMLHttpRequest) {
   xmlhttp=new XMLHttpRequest();
 } else {
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4 && xmlhttp.status==200) {
     document.getElementById("MooseLoose").innerHTML=xmlhttp.responseText;
   }
 }
 xmlhttp.open("GET","Game02.php?Team=<?php echo $Team; ?>&Question="+str,true);
 xmlhttp.send();
}

</script>
<style>
.drop{width:200px;background-color:#eee;border:0px}
</style>
</head>
<body>

<form>
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="Not Answered | <?php echo $Contestant;?>">Ready
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="True | <?php echo $Contestant;?>" onchange="showUser(this.value)" >True
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="False | <?php echo $Contestant;?>" onchange="showUser(this.value)" >False
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="A | <?php echo $Contestant;?>" onchange="showUser(this.value)" >A
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="B | <?php echo $Contestant;?>" onchange="showUser(this.value)" >B
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="C | <?php echo $Contestant;?>" onchange="showUser(this.value)" >C
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="D | <?php echo $Contestant;?>" onchange="showUser(this.value)" >D
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="E | <?php echo $Contestant;?>" onchange="showUser(this.value)" >E
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="F | <?php echo $Contestant;?>" onchange="showUser(this.value)" >F
<br>
<INPUT TYPE="Radio" NAME="Team" VALUE="All of the Above | <?php echo $Contestant;?>" onchange="showUser(this.value)" >All of the above
<br>

</form>

<br>
<div id="MooseLoose"><b></b></div>

</body>
</html>

##############################################################################
##############################################################################
########################## Game03.php ###################################

<script>
function showUser(str) {
 if (str=="") {
   document.getElementById("MooseLoose").innerHTML="";
   return;
 }
 if (window.XMLHttpRequest) {
   xmlhttp=new XMLHttpRequest();
 } else {
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4 && xmlhttp.status==200) {
     document.getElementById("MooseLoose").innerHTML=xmlhttp.responseText;
   }
 }
 xmlhttp.open("GET","Game04.php?Team="+str,true);
 xmlhttp.send();
}
</script>
<form>
<?php
$conn = mysql_connect("HOSTNAME", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE");
$result=mysql_select_db($dbName,$conn);
echo" <select name=\"Team\" onchange=\"showUser(this.value)\"> <option Value=\"%\"> ";
$results= mysql_query("SELECT distinct Team from Contestants Order by 'Team'");
echo mysql_error();
if (mysql_Numrows($results)>0)
{
$numrows=mysql_NumRows($results);
$x=0;
while ($x<$numrows){
  $theName=mysql_result($results,$x,$Team);
  echo "<option value=\"$theName\">$theName</option>\n";
  $x++;
}
}
echo "</select>";
?>
</form>
</HTML>
<div id="MooseLoose"><b>Your Answers Will Be Here</b></div>

##############################################################################
##############################################################################
########################## Game04.php ###################################

<?php
$code=$_GET['code'];
$Team=$_GET['Team'];
if (isset($code))
{
if ($code == 'delete')
{
$hostname = "HOSTNAME";
$username = "USERNAME";
$password = "PASSWORD";
$dbName = "DATABASE";
$conn = mysql_connect($hostname, $username, $password, $dbName);
$result= mysql_select_db($dbName,$conn);
$query = "delete from Scores where Team='$Team' LIMIT 1";
$result = mysql_query($query);
echo "<h1>Point for $Team has been deleted</h1>";
}
elseif
($code="add")
{
$hostname = "HOSTNAME";
$username = "USERNAME";
$password = "PASSWORD";
$dbName = "DATABASE";
$conn = mysql_connect($hostname, $username, $password, $dbName);
$result= mysql_select_db($dbName,$conn);
$query = "insert into Scores (Team,Points) values ('$Team','1')" ;
$result1 = mysql_query($query, $conn);
echo "<h1>Point for $Team has been Added</h1>";
}
}
?>
<?php
$Team=$_GET['Team'];
$con = mysqli_connect('HOSTNAME','USERNAME','PASSWORD','DATABASE');
if (!$con) {
 die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"DATABASE");
$sql="SELECT * FROM Contestants WHERE Team = '$Team'";
$result = mysqli_query($con,$sql);
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'On');
?>
<style>
td{ font: 12px "arial"; font-weight: normal; color: #000000}
A:link{font-family: Arial, Helvetica, Sans-Serif; color: #009900; text-decoration: none;}
A:visited{font-family: Arial, Helvetica, Sans-Serif; color: #009900; text-decoration: none;}
A:hover{font-family: Arial, Helvetica, Sans-Serif;color: #ff0000;text-decoration: none;}
</style>
<?php
$conn = mysql_connect('HOSTNAME', 'USERNAME','PASSWORD', 'DATABASE');
$result=mysql_select_db('DATABASE',$conn);
$query = "select * from Contestants WHERE Team like '$Team' order by id" ;
$result= mysql_query($query, $conn) ;
echo "<table border=0 cellpadding=0 width=450 cellspacing=0><tr><td>";
echo "<b>Team</td>";
echo "<td>";
echo "<b>Answer</td>";
echo "<td>";
echo "<b>Place</td>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "<b>-</td>
</tr>";
$i = 0;
$sum=0;
while ($r=mysql_fetch_array($result))
{
if ($i % 2 != 0) # An odd row
  $rowColor = "#eeeeee";
else # An even row
  $rowColor = "#ffffff";
$id=$r["id"];
$Team=$r["Team"];
$Question=$r["Question"];
   $value = $r['id'];
   $sum += $value;
echo "<tr bgcolor=$rowColor>
<td>$Team</td>
<td>$Question</td>
<td>$id</td>
<td>
<a href=\"Game04.php?Team=$Team&id=$id&code=add\"><img src=\"http://mooseloose.com/edit.png\"></a>
</td>
<td>
<a href=\"Game04.php?Team=$Team&id=$id&code=delete\"><img src=\"http://mooseloose.com/delete.png\"></a>
</td>
<tr>";
$i++;
}
mysql_free_result($result);
echo "</table>";
?><br><br>

##############################################################################
##############################################################################
########################## Game05.php ###################################

<script>
function showUser(str) {
 if (str=="") {
   document.getElementById("MooseLoose").innerHTML="";
   return;
 }
 if (window.XMLHttpRequest) {
   xmlhttp=new XMLHttpRequest();
 } else {
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4 && xmlhttp.status==200) {
     document.getElementById("MooseLoose").innerHTML=xmlhttp.responseText;
   }
 }
 xmlhttp.open("GET","Game06.php?Team="+str,true);
 xmlhttp.send();
}
</script>
<form>
<?php
$conn = mysql_connect("HOSTNAME", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE");
$result=mysql_select_db($dbName,$conn);
echo" <select name=\"Team\" onchange=\"showUser(this.value)\"> <option Value=\"%\"> ";
$results= mysql_query("SELECT distinct Team from Scores Order by 'Team'");
echo mysql_error();
if (mysql_Numrows($results)>0)
{
$numrows=mysql_NumRows($results);
$x=0;
while ($x<$numrows){
  $theName=mysql_result($results,$x,$Team);
  echo "<option value=\"$theName\">$theName</option>\n";
  $x++;
}
}
echo "</select>";
?>
</form>
<div id="MooseLoose"><b>Person info will be listed here.</b></div>

##############################################################################
##############################################################################
########################## Game06.php ###################################

<?php
$code=$_GET['code'];
$Team=$_GET['Team'];
if (isset($code))
{
if ($code == 'delete')
{
$hostname = "HOSTNAME";
$username = "USERNAME";
$password = "PASSWORD";
$dbName = "DATABASE";
$conn = mysql_connect($hostname, $username, $password, $dbName);
$result= mysql_select_db($dbName,$conn);
$query = "delete from Scores where Team='$Team' LIMIT 1";
$result = mysql_query($query);
echo "<h1>Point for $Team has been deleted</h1>";
}
elseif
($code="add")
{
$hostname = "HOSTNAME";
$username = "USERNAME";
$password = "PASSWORD";
$dbName = "DATABASE";
$conn = mysql_connect($hostname, $username, $password, $dbName);
$result= mysql_select_db($dbName,$conn);
$query = "insert into Scores (Team,Points) values ('$Team','1')" ;
$result1 = mysql_query($query, $conn);
echo "<h1>Point for $Team has been Added</h1>";
}
}
?>
<?php
$Team=$_GET['Team'];
$con = mysqli_connect('HOSTNAME','USERNAME','PASSWORD','DATABASE');
if (!$con) {
 die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"DATABASE");
$sql="SELECT * FROM Scores WHERE Team = '$Team'";
$result = mysqli_query($con,$sql);
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'On');
?>
<style>
td{ font: 12px "arial"; font-weight: normal; color: #000000}
A:link{font-family: Arial, Helvetica, Sans-Serif; color: #009900; text-decoration: none;}
A:visited{font-family: Arial, Helvetica, Sans-Serif; color: #009900; text-decoration: none;}
A:hover{font-family: Arial, Helvetica, Sans-Serif;color: #ff0000;text-decoration: none;}
</style>
<?php
$conn = mysql_connect('HOSTNAME', 'USERNAME','PASSWORD', 'DATABASE');
$result=mysql_select_db('DATABASE',$conn);
$query = "select * from Scores WHERE Team like '$Team' order by id" ;
$result= mysql_query($query, $conn) ;
echo "<table border=0 cellpadding=0 width=450 cellspacing=0><tr><td>";
echo "<b>Team</td>";
echo "<td>";
echo "<b>Score</td>";
echo "<td>";
echo "<b>Total</td>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "<b>-</td>
</tr>";
$i = 0;
$sum=0;
while ($r=mysql_fetch_array($result))
{
if ($i % 2 != 0) # An odd row
  $rowColor = "#eeeeee";
else # An even row
  $rowColor = "#ffffff";
$id=$r["id"];
$Team=$r["Team"];
$Points=$r["Points"];
   $value = $r['Points'];
   $sum += $value;
echo "<tr bgcolor=$rowColor>
<td>$Team</td>
<td>$Points</td>
<td>
$sum
</td>
<td>
<a href=\"Game04.php?Team=$Team&id=$id&code=add\"><img src=\"http://mooseloose.com/edit.png\"></a>
</td>
<td>
<a href=\"Game04.php?Team=$Team&id=$id&code=delete\"><img src=\"http://mooseloose.com/delete.png\"></a>
</td>
<tr>";
$i++;
}
mysql_free_result($result);
echo "</table>";
?><br><br>

##############################################################################
##############################################################################
######################### ContestantsML.php #################################

<?php session_start();
if (isset($_GET["order"])) $order = @$_GET["order"];
if (isset($_GET["type"])) $ordtype = @$_GET["type"];
if (isset($_POST["filter"])) $filter = @$_POST["filter"];
if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"];
$wholeonly = false;
if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"];
if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"];
if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"];
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'Off'); ?>


<html>
<head>
<title>Game show</title>
<meta name="generator" http-equiv="content-type" content="text/html">

<style type="text/css">

a:link { color: #000000; text-decoration: none}
a:vlink { color: #000000; text-decoration: none}
a:hover { color:Red; text-decoration: underline}
a:active { color: 000000; text-decoration: none;  }
a { color: #000000; text-decoration: none;  }
body {background: #F7F6F1}
CITE { font-size: 14px; color: #ff0000; text-decoration: none}


/*background color behind buttons and links*/
.bd {
 background-color: #FDFDDE;
 color: #000000;
 font-family: Arial;
 font-size: 12px;
 text-align:left;
}


td{color: #1D507D; font-family: Arial; font-size: 18px;}


/*Table Border around the information*/
.tbl {
border-left: 1px solid #ffffff;
border-top: 1px solid #ffffff;
border-bottom: 1px solid #dddddd;
border-right: 1px solid #dddddd;
 background-color: #F7F6F1;
}


/*Footer background and TH*/
.hr {
 background-color: #EAF3FA;
 color: #1D507D;
 font-family: Arial;
 font-size: 14px;
}


/*Links in the TH*/

.hr a:link{
 background-color: transparent;
 color: #1D507D;
 font-family: Arial;
 font-size: 14px;
}


/*Header*/
.th01{
background-image:url(http://mooseloose.com/header.png);
height:107px;
 background-color: #F7F6F1;
background-repeat:no-repeat;
border: 0px solid black;
}


/*Links in th main page*/
a.hr:link {
 color: #1D507D;
 font-family: Arial;
 font-size: 12px;
}


a.hr:visited {
 color: #1D507D;
}


a.hr:hover {
 color: #0000ff;
}


a.hr:active {
 color: #ff0000;
}


/*odd and bg of record details*/
.dr {
 background-color: #F7F6F1;
 color: #000000;
 font-family: Arial;
 font-size: 12px;
}


/*even*/
.sr {
 background-color: #FDFDDE;
 color: #000000;
 font-family: Arial;
 font-size: 12px;
}


.detaillabels{width:100px;
text-align:right;
font-family: Arial;
font-size: 14px;
background-color: #EAF3FA;
}


.op02
a {
font-family: Arial;
font-size: 12px;
color: #EAF3FA;
text-decoration: none;
float: left;
background-image: url(butaX.jpg);
background-color: #21759B;
text-align: center;
vertical-align: middle;
border-style: solid;
border-width: 1px;
border-color: white #C7C7C7 #C7C7C7 white;
top: 10px;
left: 10px;
width:100px;
height:18px;
overflow: visible;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-khtml-border-radius: 50px;
border-radius: 50px; }


.op02
a:hover {
color: #ffffff;
text-decoration: none;
float: left;
background-image: url(butbX.jpg);
background-color: #073447;
text-align: center;
vertical-align: middle;
border-style: solid;
border-width: 1px;
border-color: #C7C7C7 white white #C7C7C7;
top: 10px;
left: 10px;
width:100px;
height:18px;
overflow: visible }


table{width:960px;}


.search{width:500px}


.success{ font-family: Arial;
font-size: 14px;
}

</style> </head>
<body>
<center><table border=0><tr><td valign=top class="th01"></table>
<table>
<tr>


<td valign=top valign="top">
<?php
if (!login()) exit;
?><div style="float: right"><span class="op02 "><a href="ContestantsML.php?a=logout">Logout</a></span></div>
<div style="float: right"><span class="op02 "><a href="Contestantsexcel.php?a=logout">Excel</a></span></div>
<br>
<?php
$conn = connect();
$showrecs = 20;
$pagerange = 10;


$a = @$_GET["a"];
$recid = @$_GET["recid"];
$page = @$_GET["page"];
if (!isset($page)) $page = 1;


$sql = @$_POST["sql"];


switch ($sql) {
  case "insert":
    sql_insert();
    break;
  case "update":
    sql_update();
    break;
  case "delete":
    sql_delete();
    break;
}


switch ($a) {
  case "add":
    addrec();
    break;
  case "view":
    viewrec($recid);
    break;
  case "edit":
    editrec($recid);
    break;
  case "del":
    deleterec($recid);
    break;
  default:
    select();
    break;
}


if (isset($order)) $_SESSION["order"] = $order;
if (isset($ordtype)) $_SESSION["type"] = $ordtype;
if (isset($filter)) $_SESSION["filter"] = $filter;
if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;


mysql_close($conn);
?>
</td></tr></table>
<table ><tr><td valign=top class="hr">Moose Loose
</td></tr></table>
</body>
</html>


<?php function select()
{
global $a;
global $showrecs;
global $page;
global $filter;
global $filterfield;
global $wholeonly;
global $order;
global $ordtype;


if ($a == "reset") {
  $filter = "";
  $filterfield = "";
  $wholeonly = "";
  $order = "";
  $ordtype = "";
}


$checkstr = "";
if ($wholeonly) $checkstr = " checked";
if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }


$res = sql_select();
$count = sql_getrecordcount();
if ($count % $showrecs != 0) {
  $pagecount = intval($count / $showrecs) + 1;
}
else {
  $pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {mysql_data_seek($res, $startrec);}
$reccount = min($showrecs * $page, $count);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Records shown <?php echo $startrec + 1 ?> - <?php echo $reccount ?> of <?php echo $count ?></td></tr>
</table>
<form name="Contestants" action="ContestantsML.php" method="post">
<table class="search" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Find</b>&nbsp;</td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td>

<select name="filter_field">
<option value="">All Fields</option>
<option value="<?php echo "Id" ?>"<?php if ($filterfield == "Id") { echo "selected"; } ?>><?php echo htmlspecialchars("Id") ?></option>
<option value="<?php echo "Team" ?>"<?php if ($filterfield == "Team") { echo "selected"; } ?>><?php echo htmlspecialchars("Team") ?></option>
<option value="<?php echo "Question" ?>"<?php if ($filterfield == "Question") { echo "selected"; } ?>><?php echo htmlspecialchars("Question") ?></option>
<option value="<?php echo "Time" ?>"<?php if ($filterfield == "Time") { echo "selected"; } ?>><?php echo htmlspecialchars("Time") ?></option>
</select>


</td>


<td><nobr><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Whole words only</td>
</td>
<td>&nbsp;</td>
<td><input type="submit" name="action" value="Search Now"></td>
<td></td>
</tr>
</table>
</form>


<?php showpagenav($page, $pagecount); ?>
<br>


<!--------------------------------------------------------------------------view all table--------------------------------------------------->

<table class="tbl" border="0" cellspacing="1" cellpadding="5">
<tr>
<td valign=top class="hr">&nbsp;</td>
<td valign=top class="hr">&nbsp;</td>
<td valign=top class="hr">&nbsp;</td>
<td valign=top class="hr"><a class="hr" href="ContestantsML.php?order=<?php echo "Id" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Id") ?></a></td>


<td valign=top class="hr">
<a class="hr" href="ContestantsML.php?order=<?php echo "Team" ?>&type=<?php echo $ordtypestr ?>">
<?php echo htmlspecialchars("Team") ?></a></td>
<td valign=top class="hr">
<a class="hr" href="ContestantsML.php?order=<?php echo "Question" ?>&type=<?php echo $ordtypestr ?>">
<?php echo htmlspecialchars("Question") ?></a></td>
<td valign=top class="hr">
<a class="hr" href="ContestantsML.php?order=<?php echo "Time" ?>&type=<?php echo $ordtypestr ?>">
<?php echo htmlspecialchars("Time") ?></a></td>

</tr>
<?php
for ($i = $startrec; $i < $reccount; $i++)
{
  $row = mysql_fetch_assoc($res);
  $style = "dr";
  if ($i % 2 != 0) {
    $style = "sr";
  }
?>
<tr>

<td width=10 valign=top class="<?php echo $style ?>"><a href="ContestantsML.php?a=view&recid=<?php echo $i ?>"><img src="http://mooseloose.com/view.png" border=0 width=20 height=20></a></td>
<td width=10 valign=top class="<?php echo $style ?>"><a href="ContestantsML.php?a=edit&recid=<?php echo $i ?>"><img src="http://mooseloose.com/edit.png" border=0 width=20 height=20></a></td>
<td width=10 valign=top class="<?php echo $style ?>"><a href="ContestantsML.php?a=del&recid=<?php echo $i ?>"><img src="http://mooseloose.com/delete.png" border=0 width=20 height=20></a></td>


<td valign=top class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Id"]) ?></td>
<td valign=top class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Team"]) ?></td>
<td valign=top class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Question"]) ?></td>
<td valign=top class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Time"]) ?></td>
</tr>
<?php
}
mysql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount); ?>
<?php } ?>


                      <?php function login()
                      {
                      global $_POST;
                      global $_SESSION;


                      global $_GET;
                      if (isset($_GET["a"]) && ($_GET["a"] == 'logout')) $_SESSION["logged_in"] = false;
                      if (!isset($_SESSION["logged_in"])) $_SESSION["logged_in"] = false;
                      if (!$_SESSION["logged_in"]) {
                      $login = "";
                      $password = "";
                      if (isset($_POST["login"])) $login = @$_POST["login"];
                      if (isset($_POST["password"])) $password = @$_POST["password"];


                      if (($login != "") && ($password != "")) {
                      if (($login == "admin") && ($password == "admin")) {
                      $_SESSION["logged_in"] = true;
                      }
                      else {
                      ?>


<p><b><font color="-1">Sorry, the login/password combination you've entered is invalid</font></b></p>
<?php } } }if (isset($_SESSION["logged_in"]) && (!$_SESSION["logged_in"])) { ?>
<form name=Contestants action="ContestantsML.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td>Username</td>
<td><input type="text" name="login" value="<?php echo $login ?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" value="<?php echo $password ?>"></td>
</tr>
<tr>
<td><input type="submit" name="action" value="Login"></td>
</tr>
</table>
</form>
<?php
}
if (!isset($_SESSION["logged_in"])) $_SESSION["logged_in"] = false;
return $_SESSION["logged_in"];
} ?>


<?php function showrow($row, $recid)
{
?>


<!--------------------------------------------------------------------------View Record Detail------------------>


<table class="tbl" border="0" cellspacing="1" cellpadding="5">
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Id")."&nbsp;" ?></td>
<td valign=top class="dr"><?php echo htmlspecialchars($row["Id"]) ?></td>
</tr>
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Team")."&nbsp;" ?></td>
<td valign=top class="dr"><?php echo htmlspecialchars($row["Team"]) ?></td>
</tr>
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Question")."&nbsp;" ?></td>
<td valign=top class="dr"><?php echo htmlspecialchars($row["Question"]) ?></td>
</tr>
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Time")."&nbsp;" ?></td>
<td valign=top class="dr"><?php echo htmlspecialchars($row["Time"]) ?></td>
</tr>
</table>
<?php } ?>


<?php function showroweditor($row, $iseditmode)
{
global $conn;
?>


<!--------------------------------------------Add and Edit Page------------------------------------------------------------->


<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">

<input type="hidden" name="Id"  size="55" value="<?php echo str_replace('"', '&quot;', trim($row["Id"])) ?>">

<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Team")."&nbsp;" ?></td>
<td valign=top class="dr"><input type="text" name="Team" maxlength="250" size="55" value="<?php echo str_replace('"', '&quot;', trim($row["Team"])) ?>"></td>
</tr>
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Question")."&nbsp;" ?></td>
<td valign=top class="dr"><input type="text" name="Question" maxlength="250" size="55" value="<?php echo str_replace('"', '&quot;', trim($row["Question"])) ?>"></td>
</tr>
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Time")."&nbsp;" ?></td>
<td valign=top class="dr"><input type="text" name="Time" maxlength="250" size="55" value="<?php echo str_replace('"', '&quot;', trim($row["Time"])) ?>"></td>
</tr>
</table>
<?php } ?>


<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><span class="op02 "><a href="ContestantsML.php?a=add">Add Record</a>&nbsp;<span class="op02"><a href="ContestantsML.php?a=reset">List All Records</a></span></td>
<?php if ($page > 1) { ?>
<td><a href="ContestantsML.php?page=<?php echo $page - 1 ?>">&lt;&lt;&nbsp;Prev</a>&nbsp;</td>
<?php } ?>
<?php
global $pagerange;


if ($pagecount > 1) {


if ($pagecount % $pagerange != 0) {
  $rangecount = intval($pagecount / $pagerange) + 1;
}
else {
  $rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
  $startpage = (($i - 1) * $pagerange) + 1;
  $count = min($i * $pagerange, $pagecount);


  if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
    for ($j = $startpage; $j < $count + 1; $j++) {
      if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="ContestantsML.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="ContestantsML.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td>&nbsp;<a href="ContestantsML.php?page=<?php echo $page + 1 ?>">Next&nbsp;&gt;&gt;</a>&nbsp;</td>
<?php } ?>
</tr>
</table>
<?php } ?>


<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><span class="op02 "><a href="ContestantsML.php">Index Page</a>
<?php if ($recid > 0) { ?>
<span class="op02 "><a href="ContestantsML.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Prior Record</a>
<?php } if ($recid < $count - 1) { ?>
<span class="op02 "><a href="ContestantsML.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Next Record</a></td>
<?php } ?>
</tr>
</table>


<?php } ?>


<?php function addrec()
{
?>

<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><span class="op02 "><a href="ContestantsML.php">Index Page</a></td>
</tr>
</table>


<form name="Contestants" enctype="multipart/form-data" action="ContestantsML.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
"Id" => "",
"Team" => "",
"Question" => "",
"Time" => ""
);
showroweditor($row, false);
?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php } ?>


<?php function viewrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<br>


<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><span class="op02 "><a href="ContestantsML.php?a=add">Add Record</a>
<span class="op02 "><a href="ContestantsML.php?a=edit&recid=<?php echo $recid ?>">Edit Record</a></td>
<td><span class="op02 "><a href="ContestantsML.php?a=del&recid=<?php echo $recid ?>">Delete Record</a></td>
</tr>
</table>
<?php
mysql_free_result($res);
} ?>


<?php function editrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("edit", $recid, $count);
?>
<br>
<form name="Contestants" enctype="multipart/form-data" action="ContestantsML.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xId" value="<?php echo $row["Id"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php
mysql_free_result($res);
} ?>


<?php function deleterec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("del", $recid, $count);
?>
<br>
<form name="Contestants" action="ContestantsML.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xId" value="<?php echo $row["Id"] ?>">
<?php showrow($row, $recid) ?>
<p><input type="submit" name="action" value="Confirm"></p>
</form>
<?php
mysql_free_result($res);
} ?>


<?php function connect()
{
$conn = mysql_connect("HOSTNAME", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE");
return $conn;
}


function sqlvalue($val, $quote)
{
if ($quote)
  $tmp = sqlstr($val);
else
  $tmp = $val;
if ($tmp == "")
  $tmp = "NULL";
elseif ($quote)
  $tmp = "'".$tmp."'";
return $tmp;
}


function sqlstr($val)
{
return str_replace("'", "'", $val);
}


function sql_select()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;


$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT `Id`,
`Team`,
`Question`,
`Time`
FROM `Contestants`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
  $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
  $sql .= " where
(`Id` like '" .$filterstr ."') or
(`Team` like '" .$filterstr ."') or
(`Question` like '" .$filterstr ."') or
(`Time` like '" .$filterstr ."')
";
}
if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = mysql_query($sql, $conn) or die(mysql_error());
return $res;
}


function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;


$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT COUNT(*) FROM `Contestants`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
  $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
  $sql .= " where
(`Id` like '" .$filterstr ."') or
(`Team` like '" .$filterstr ."') or
(`Question` like '" .$filterstr ."') or
(`Time` like '" .$filterstr ."')
";
}
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
reset($row);
return current($row);
}


function sql_insert()
{
global $conn;
global $_POST;


$sql = "insert into `Contestants`
(`Id`,
`Team`,
`Question`,
`Time`
) values (
" .sqlvalue(@$_POST["Id"], false).",
" .sqlvalue(@$_POST["Team"], true).",
" .sqlvalue(@$_POST["Question"], true).",
" .sqlvalue(@$_POST["Time"], true)."
)";
mysql_query($sql, $conn) or die(mysql_error());
}


function sql_update()
{
global $conn;
global $_POST;


$sql = "update `Contestants` set
`Id`=" .sqlvalue(@$_POST["Id"], false).",
`Team`=" .sqlvalue(@$_POST["Team"], true).",
`Question`=" .sqlvalue(@$_POST["Question"], true).",  
`Time`=" .sqlvalue(@$_POST["Time"], true)."
where " .primarykeycondition();
mysql_query($sql, $conn) or die(mysql_error());
}


function sql_delete()
{
global $conn;


$sql = "delete from `Contestants` where " .primarykeycondition();
mysql_query($sql, $conn) or die(mysql_error());
}
function primarykeycondition()
{
global $_POST;
$pk = "";
$pk .= "(`Id`";
if (@$_POST["xId"] == "") {
  $pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xId"], false);
};
$pk .= ")";
return $pk;
}
?>

##############################################################################
##############################################################################
########################### ScoresML.php ###############################

<?php session_start();
if (isset($_GET["order"])) $order = @$_GET["order"];
if (isset($_GET["type"])) $ordtype = @$_GET["type"];
if (isset($_POST["filter"])) $filter = @$_POST["filter"];
if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"];
$wholeonly = false;
if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"];
if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"];
if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"];
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'Off'); ?>


<html>
<head>
<title>Scores</title>
<meta name="generator" http-equiv="content-type" content="text/html">

<style type="text/css">

a:link { color: #000000; text-decoration: none}
a:vlink { color: #000000; text-decoration: none}
a:hover { color:Red; text-decoration: underline}
a:active { color: 000000; text-decoration: none;  }
a { color: #000000; text-decoration: none;  }
body {background: #F7F6F1}
CITE { font-size: 14px; color: #ff0000; text-decoration: none}


/*background color behind buttons and links*/
.bd {
 background-color: #FDFDDE;
 color: #000000;
 font-family: Arial;
 font-size: 12px;
 text-align:left;
}


td{color: #1D507D; font-family: Arial; font-size: 18px;}


/*Table Border around the information*/
.tbl {
border-left: 1px solid #ffffff;
border-top: 1px solid #ffffff;
border-bottom: 1px solid #dddddd;
border-right: 1px solid #dddddd;
 background-color: #F7F6F1;
}


/*Footer background and TH*/
.hr {
 background-color: #EAF3FA;
 color: #1D507D;
 font-family: Arial;
 font-size: 14px;
}


/*Links in the TH*/

.hr a:link{
 background-color: transparent;
 color: #1D507D;
 font-family: Arial;
 font-size: 14px;
}


/*Header*/
.th01{
background-image:url(http://mooseloose.com/header.png);
height:107px;
 background-color: #F7F6F1;
background-repeat:no-repeat;
border: 0px solid black;
}


/*Links in th main page*/
a.hr:link {
 color: #1D507D;
 font-family: Arial;
 font-size: 12px;
}


a.hr:visited {
 color: #1D507D;
}


a.hr:hover {
 color: #0000ff;
}


a.hr:active {
 color: #ff0000;
}


/*odd and bg of record details*/
.dr {
 background-color: #F7F6F1;
 color: #000000;
 font-family: Arial;
 font-size: 12px;
}


/*even*/
.sr {
 background-color: #FDFDDE;
 color: #000000;
 font-family: Arial;
 font-size: 12px;
}


.detaillabels{width:100px;
text-align:right;
font-family: Arial;
font-size: 14px;
background-color: #EAF3FA;
}


.op02
a {
font-family: Arial;
font-size: 12px;
color: #EAF3FA;
text-decoration: none;
float: left;
background-image: url(butaX.jpg);
background-color: #21759B;
text-align: center;
vertical-align: middle;
border-style: solid;
border-width: 1px;
border-color: white #C7C7C7 #C7C7C7 white;
top: 10px;
left: 10px;
width:100px;
height:18px;
overflow: visible;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-khtml-border-radius: 50px;
border-radius: 50px; }


.op02
a:hover {
color: #ffffff;
text-decoration: none;
float: left;
background-image: url(butbX.jpg);
background-color: #073447;
text-align: center;
vertical-align: middle;
border-style: solid;
border-width: 1px;
border-color: #C7C7C7 white white #C7C7C7;
top: 10px;
left: 10px;
width:100px;
height:18px;
overflow: visible }


table{width:960px;}


.search{width:500px}


.success{ font-family: Arial;
font-size: 14px;
}

</style> </head>
<body>
<center><table border=0><tr><td valign=top class="th01"></table>
<table>
<tr>


<td valign=top valign="top">
<?php
if (!login()) exit;
?><div style="float: right"><span class="op02 "><a href="ScoresML.php?a=logout">Logout</a></span></div>
<div style="float: right"><span class="op02 "><a href="Scoresexcel.php?a=logout">Excel</a></span></div>
<br>
<?php
$conn = connect();
$showrecs = 20;
$pagerange = 10;


$a = @$_GET["a"];
$recid = @$_GET["recid"];
$page = @$_GET["page"];
if (!isset($page)) $page = 1;


$sql = @$_POST["sql"];


switch ($sql) {
  case "insert":
    sql_insert();
    break;
  case "update":
    sql_update();
    break;
  case "delete":
    sql_delete();
    break;
}


switch ($a) {
  case "add":
    addrec();
    break;
  case "view":
    viewrec($recid);
    break;
  case "edit":
    editrec($recid);
    break;
  case "del":
    deleterec($recid);
    break;
  default:
    select();
    break;
}


if (isset($order)) $_SESSION["order"] = $order;
if (isset($ordtype)) $_SESSION["type"] = $ordtype;
if (isset($filter)) $_SESSION["filter"] = $filter;
if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;


mysql_close($conn);
?>
</td></tr></table>
<table ><tr><td valign=top class="hr">Scores
</td></tr></table>
</body>
</html>


<?php function select()
{
global $a;
global $showrecs;
global $page;
global $filter;
global $filterfield;
global $wholeonly;
global $order;
global $ordtype;


if ($a == "reset") {
  $filter = "";
  $filterfield = "";
  $wholeonly = "";
  $order = "";
  $ordtype = "";
}


$checkstr = "";
if ($wholeonly) $checkstr = " checked";
if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }


$res = sql_select();
$count = sql_getrecordcount();
if ($count % $showrecs != 0) {
  $pagecount = intval($count / $showrecs) + 1;
}
else {
  $pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {mysql_data_seek($res, $startrec);}
$reccount = min($showrecs * $page, $count);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Records shown <?php echo $startrec + 1 ?> - <?php echo $reccount ?> of <?php echo $count ?></td></tr>
</table>
<form name="Scores" action="ScoresML.php" method="post">
<table class="search" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Find</b>&nbsp;</td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td>

<select name="filter_field">
<option value="">All Fields</option>
<option value="<?php echo "Id" ?>"<?php if ($filterfield == "Id") { echo "selected"; } ?>><?php echo htmlspecialchars("Id") ?></option>
<option value="<?php echo "Team" ?>"<?php if ($filterfield == "Team") { echo "selected"; } ?>><?php echo htmlspecialchars("Team") ?></option>
<option value="<?php echo "Points" ?>"<?php if ($filterfield == "Points") { echo "selected"; } ?>><?php echo htmlspecialchars("Points") ?></option>
</select>


</td>


<td><nobr><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Whole words only</td>
</td>
<td>&nbsp;</td>
<td><input type="submit" name="action" value="Search Now"></td>
<td></td>
</tr>
</table>
</form>


<?php showpagenav($page, $pagecount); ?>
<br>


<!--------------------------------------------------------------------------view all table--------------------------------------------------->

<table class="tbl" border="0" cellspacing="1" cellpadding="5">
<tr>
<td valign=top class="hr">&nbsp;</td>
<td valign=top class="hr">&nbsp;</td>
<td valign=top class="hr">&nbsp;</td>
<td valign=top class="hr"><a class="hr" href="ScoresML.php?order=<?php echo "Id" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Id") ?></a></td>


<td valign=top class="hr">
<a class="hr" href="ScoresML.php?order=<?php echo "Team" ?>&type=<?php echo $ordtypestr ?>">
<?php echo htmlspecialchars("Team") ?></a></td>
<td valign=top class="hr">
<a class="hr" href="ScoresML.php?order=<?php echo "Points" ?>&type=<?php echo $ordtypestr ?>">
<?php echo htmlspecialchars("Points") ?></a></td>

</tr>
<?php
for ($i = $startrec; $i < $reccount; $i++)
{
  $row = mysql_fetch_assoc($res);
  $style = "dr";
  if ($i % 2 != 0) {
    $style = "sr";
  }
?>
<tr>

<td width=10 valign=top class="<?php echo $style ?>"><a href="ScoresML.php?a=view&recid=<?php echo $i ?>"><img src="http://mooseloose.com/view.png" border=0 width=20 height=20></a></td>
<td width=10 valign=top class="<?php echo $style ?>"><a href="ScoresML.php?a=edit&recid=<?php echo $i ?>"><img src="http://mooseloose.com/edit.png" border=0 width=20 height=20></a></td>
<td width=10 valign=top class="<?php echo $style ?>"><a href="ScoresML.php?a=del&recid=<?php echo $i ?>"><img src="http://mooseloose.com/delete.png" border=0 width=20 height=20></a></td>


<td valign=top class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Id"]) ?></td>
<td valign=top class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Team"]) ?></td>
<td valign=top class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Points"]) ?></td>
</tr>
<?php
}
mysql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount); ?>
<?php } ?>


                      <?php function login()
                      {
                      global $_POST;
                      global $_SESSION;


                      global $_GET;
                      if (isset($_GET["a"]) && ($_GET["a"] == 'logout')) $_SESSION["logged_in"] = false;
                      if (!isset($_SESSION["logged_in"])) $_SESSION["logged_in"] = false;
                      if (!$_SESSION["logged_in"]) {
                      $login = "";
                      $password = "";
                      if (isset($_POST["login"])) $login = @$_POST["login"];
                      if (isset($_POST["password"])) $password = @$_POST["password"];


                      if (($login != "") && ($password != "")) {
                      if (($login == "admin") && ($password == "admin")) {
                      $_SESSION["logged_in"] = true;
                      }
                      else {
                      ?>


<p><b><font color="-1">Sorry, the login/password combination you've entered is invalid</font></b></p>
<?php } } }if (isset($_SESSION["logged_in"]) && (!$_SESSION["logged_in"])) { ?>
<form name=Scores action="ScoresML.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td>Username</td>
<td><input type="text" name="login" value="<?php echo $login ?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" value="<?php echo $password ?>"></td>
</tr>
<tr>
<td><input type="submit" name="action" value="Login"></td>
</tr>
</table>
</form>
<?php
}
if (!isset($_SESSION["logged_in"])) $_SESSION["logged_in"] = false;
return $_SESSION["logged_in"];
} ?>


<?php function showrow($row, $recid)
{
?>


<!--------------------------------------------------------------------------View Record Detail------------------>


<table class="tbl" border="0" cellspacing="1" cellpadding="5">
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Id")."&nbsp;" ?></td>
<td valign=top class="dr"><?php echo htmlspecialchars($row["Id"]) ?></td>
</tr>
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Team")."&nbsp;" ?></td>
<td valign=top class="dr"><?php echo htmlspecialchars($row["Team"]) ?></td>
</tr>
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Points")."&nbsp;" ?></td>
<td valign=top class="dr"><?php echo htmlspecialchars($row["Points"]) ?></td>
</tr>
</table>
<?php } ?>


<?php function showroweditor($row, $iseditmode)
{
global $conn;
?>


<!--------------------------------------------Add and Edit Page------------------------------------------------------------->


<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">

<input type="hidden" name="Id"  size="55" value="<?php echo str_replace('"', '&quot;', trim($row["Id"])) ?>">

<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Team")."&nbsp;" ?></td>
<td valign=top class="dr"><input type="text" name="Team" maxlength="250" size="55" value="<?php echo str_replace('"', '&quot;', trim($row["Team"])) ?>"></td>
</tr>
<tr>
<td valign=top class="detaillabels"><nobr><?php echo htmlspecialchars("Points")."&nbsp;" ?></td>
<td valign=top class="dr"><input type="text" name="Points" maxlength="250" size="55" value="<?php echo str_replace('"', '&quot;', trim($row["Points"])) ?>"></td>
</tr>
</table>
<?php } ?>


<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><span class="op02 "><a href="ScoresML.php?a=add">Add Record</a>&nbsp;<span class="op02"><a href="ScoresML.php?a=reset">List All Records</a></span></td>
<?php if ($page > 1) { ?>
<td><a href="ScoresML.php?page=<?php echo $page - 1 ?>">&lt;&lt;&nbsp;Prev</a>&nbsp;</td>
<?php } ?>
<?php
global $pagerange;


if ($pagecount > 1) {


if ($pagecount % $pagerange != 0) {
  $rangecount = intval($pagecount / $pagerange) + 1;
}
else {
  $rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
  $startpage = (($i - 1) * $pagerange) + 1;
  $count = min($i * $pagerange, $pagecount);


  if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
    for ($j = $startpage; $j < $count + 1; $j++) {
      if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="ScoresML.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="ScoresML.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td>&nbsp;<a href="ScoresML.php?page=<?php echo $page + 1 ?>">Next&nbsp;&gt;&gt;</a>&nbsp;</td>
<?php } ?>
</tr>
</table>
<?php } ?>


<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><span class="op02 "><a href="ScoresML.php">Index Page</a>
<?php if ($recid > 0) { ?>
<span class="op02 "><a href="ScoresML.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Prior Record</a>
<?php } if ($recid < $count - 1) { ?>
<span class="op02 "><a href="ScoresML.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Next Record</a></td>
<?php } ?>
</tr>
</table>


<?php } ?>


<?php function addrec()
{
?>

<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><span class="op02 "><a href="ScoresML.php">Index Page</a></td>
</tr>
</table>


<form name="Scores" enctype="multipart/form-data" action="ScoresML.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
"Id" => "",
"Team" => "",
"Points" => ""
);
showroweditor($row, false);
?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php } ?>


<?php function viewrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<br>


<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><span class="op02 "><a href="ScoresML.php?a=add">Add Record</a>
<span class="op02 "><a href="ScoresML.php?a=edit&recid=<?php echo $recid ?>">Edit Record</a></td>
<td><span class="op02 "><a href="ScoresML.php?a=del&recid=<?php echo $recid ?>">Delete Record</a></td>
</tr>
</table>
<?php
mysql_free_result($res);
} ?>


<?php function editrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("edit", $recid, $count);
?>
<br>
<form name="Scores" enctype="multipart/form-data" action="ScoresML.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xId" value="<?php echo $row["Id"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php
mysql_free_result($res);
} ?>


<?php function deleterec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("del", $recid, $count);
?>
<br>
<form name="Scores" action="ScoresML.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xId" value="<?php echo $row["Id"] ?>">
<?php showrow($row, $recid) ?>
<p><input type="submit" name="action" value="Confirm"></p>
</form>
<?php
mysql_free_result($res);
} ?>


<?php function connect()
{
$conn = mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE");
return $conn;
}


function sqlvalue($val, $quote)
{
if ($quote)
  $tmp = sqlstr($val);
else
  $tmp = $val;
if ($tmp == "")
  $tmp = "NULL";
elseif ($quote)
  $tmp = "'".$tmp."'";
return $tmp;
}


function sqlstr($val)
{
return str_replace("'", "'", $val);
}


function sql_select()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;


$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT `Id`,
`Team`,
`Points`
FROM `Scores`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
  $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
  $sql .= " where
(`Id` like '" .$filterstr ."') or
(`Team` like '" .$filterstr ."') or
(`Points` like '" .$filterstr ."')
";
}
if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = mysql_query($sql, $conn) or die(mysql_error());
return $res;
}


function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;


$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT COUNT(*) FROM `Scores`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
  $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
  $sql .= " where
(`Id` like '" .$filterstr ."') or
(`Team` like '" .$filterstr ."') or
(`Points` like '" .$filterstr ."')
";
}
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
reset($row);
return current($row);
}


function sql_insert()
{
global $conn;
global $_POST;


$sql = "insert into `Scores`
(`Id`,
`Team`,
`Points`
) values (
" .sqlvalue(@$_POST["Id"], false).",
" .sqlvalue(@$_POST["Team"], true).",
" .sqlvalue(@$_POST["Points"], true)."
)";
mysql_query($sql, $conn) or die(mysql_error());
}


function sql_update()
{
global $conn;
global $_POST;


$sql = "update `Scores` set
`Id`=" .sqlvalue(@$_POST["Id"], false).",
`Team`=" .sqlvalue(@$_POST["Team"], true).",
`Points`=" .sqlvalue(@$_POST["Points"], true)."
where " .primarykeycondition();
mysql_query($sql, $conn) or die(mysql_error());
}


function sql_delete()
{
global $conn;


$sql = "delete from `Scores` where " .primarykeycondition();
mysql_query($sql, $conn) or die(mysql_error());
}
function primarykeycondition()
{
global $_POST;
$pk = "";
$pk .= "(`Id`";
if (@$_POST["xId"] == "") {
  $pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xId"], false);
};
$pk .= ")";
return $pk;
}
?>

##############################################################################
##############################################################################
######################### truncate.php ####################################

<?php
$con=mysqli_connect("HOSTNAME","USERNAME","PASSWORD","DATABASE");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="TRUNCATE TABLE Contestants";
if (mysqli_query($con,$sql))
{
echo "Table Emptied";
}
else
{
echo "Error: " . mysqli_error($con);
}
?>

##############################################################################
##############################################################################
########################## truncate2.php ##################################

<?php
$con=mysqli_connect("HOSTNAME","USERNAME","PASSWORD","DATABASE");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="TRUNCATE TABLE Scores";
if (mysqli_query($con,$sql))
{
echo "Table Emptied";
}
else
{
echo "Error: " . mysqli_error($con);
}
?>

##############################################################################
##############################################################################
############################## Game02.php #####################################

<table class="FearFarm" border="0" cellpadding="5" cellspacing="2" width="600">
<?php
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'On');
ini_set('log_errors', 'On');
ini_set('error_log', '/path/to/error_log');
$Team=$_GET['Team'];
$Question=$_GET['Question'];
$todae=date ("Y/m/d-G:i");
$ip = getenv('REMOTE_ADDR');
$headercolor="#000000";
$colorodd="#ffffff";
$coloreven="#cccccc";
$hostname = "HOSTNAME";
$username = "USERNAME";
$password = "PASSWORD";
$dbName = "DATABASE";
$conn = mysql_connect($hostname, $username, $password, $dbName);
$result= mysql_select_db($dbName,$conn);
$query = "insert into Contestants (todae, ip, Team,Question) values ('$todae','$ip', '$Team', '$Question')" ;
$result1 = mysql_query($query, $conn);
echo "<p class=\".success\">You Answered <b>$Question</b>!</p>";
?>