<?
// scoreinput.php - input a match score when match selected from list
?>
<html>
<head>
<basefont face="Verdana">
</head>
<body>
<!-- standard page header begins -->
<p> <p>
<table width="100%" cellspacing="0" cellpadding="5" >
<tr>
<td></td>
</tr>
<tr>
<td bgcolor="Red">< font size="-1" color="White">< b>Cornwall County
Short Mat Bowling Association : Administration :
League Results : Edit</b></font></td>
</tr>
</table>
<!-- standard page header ends -->
<p>
<?
// includes
include("../conf.php");
include("../functions.php") ;
// form not yet submitted
// display initial form with values pre-filled
if (!$submit)
{
// open database connection
$connection = mysql_connect($ host, $user, $pass) or die ("Unable to
connect!");
// select database
mysql_select_db ($db) or die ("Unable to select database!");
// generate and execute query
$query = "SELECT * FROM matches WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " .
mysql_error());
// if a result is returned
if (mysql_num_rows ($result) > 0)
{
// turn it into an object
$row = mysql_fetch_obj ect($result);
// print form with values pre-filled
?>
<table cellspacing="5" cellpadding="5" >
<form action="<? echo $PHP_SELF; ?>" method="POST">
<input type="hidden" name="id" value="<? echo $row->id; ?>">
<tr>
<td valign="top"><b >Date<b></td>
<td><? echo $row->date; ?></td>
</tr>
<tr>
<td valign="top"><b ><? echo $row->home_team; ?></b></td>
<td><input size="5" name="home_shot s" value="<? echo
$row->home_shots; ?>"></td>
</tr>
<tr>
<td valign="top"><b ><? echo $row->away_team; ?></b></td>
<td><input size="5" name="away_shot s" value="<? echo
$row->away_shots; ?>"></td>
</tr>
<tr>
<td valign="top"><b >Match Completed</b></td>
<td><input type="checkbox" name="completed " value="Y"></td>
</tr>
<tr>
<td colspan=2><inpu t type="Submit" name="submit" value="Update"> </td>
</tr>
</form>
</table>
<?
}
// no result returned
// print graceful error message
else
{
echo "<font size=-1>That match could not be located in our
database.</font>";
}
}
// form submitted
// start processing it
else
{
// set up error list array
$errorList = array();
$count = 0;
// check for errors
// if none found...
if (sizeof($errorL ist) == 0)
{
// open database connection
$connection = mysql_connect($ host, $user, $pass) or die ("Unable to
connect!");
// select database
mysql_select_db ($db) or die ("Unable to select database!");
// generate and execute query
if ($home_shots > $away_shots) {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryhome = "UPDATE teams
SET played = played + 1,
won = won + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots',
points = points + 2 WHERE team = '$home_team'";
$queryaway = "UPDATE teams
SET played = played + 1,
lost = lost + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots' WHERE team = '$away_team'";
} elseif ($home_shots < $away_shots) {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryaway = "UPDATE teams
SET played = played + 1,
won = won + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots',
points = points + 2 WHERE team = '$away_team'";
$queryhome = "UPDATE teams
SET played = played + 1,
lost = lost + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots' WHERE team = '$home_team'";
} else {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryhome = "UPDATE teams
SET played = played + 1,
drawn = drawn + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots',
points = points + 1 WHERE team = '$home_team'";
$queryaway = "UPDATE teams
SET played = played + 1,
drawn = drawn + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots',
points = points + 1 WHERE team = '$away_team'";
}
$result1 = mysql_query($qu erymatches) or die ("Error in query:
$query. " . mysql_error());
$result2 = mysql_query($qu eryhome) or die ("Error in query: $query.
" . mysql_error());
$result3 = mysql_query($qu eryaway) or die ("Error in query: $query.
" . mysql_error());
// print result
echo "<font size=-1>Update successful. <a href=list.php>G o back to
the main menu</a>.</font>";
// close database connection
mysql_close($co nnection);
}
else
{
// errors occurred
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($erro rList); $x++)
{
echo "<li>$error List[$x]";
}
echo "</ul></font>";
}
}
?>
<!-- standard page footer begins -->
<p>
<table width="100%" cellspacing="0" cellpadding="5" >
<tr>
<td align="center"> </td>
</tr>
</table>
<!-- standard page footer ends -->
</body>
</html>
// scoreinput.php - input a match score when match selected from list
?>
<html>
<head>
<basefont face="Verdana">
</head>
<body>
<!-- standard page header begins -->
<p> <p>
<table width="100%" cellspacing="0" cellpadding="5" >
<tr>
<td></td>
</tr>
<tr>
<td bgcolor="Red">< font size="-1" color="White">< b>Cornwall County
Short Mat Bowling Association : Administration :
League Results : Edit</b></font></td>
</tr>
</table>
<!-- standard page header ends -->
<p>
<?
// includes
include("../conf.php");
include("../functions.php") ;
// form not yet submitted
// display initial form with values pre-filled
if (!$submit)
{
// open database connection
$connection = mysql_connect($ host, $user, $pass) or die ("Unable to
connect!");
// select database
mysql_select_db ($db) or die ("Unable to select database!");
// generate and execute query
$query = "SELECT * FROM matches WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " .
mysql_error());
// if a result is returned
if (mysql_num_rows ($result) > 0)
{
// turn it into an object
$row = mysql_fetch_obj ect($result);
// print form with values pre-filled
?>
<table cellspacing="5" cellpadding="5" >
<form action="<? echo $PHP_SELF; ?>" method="POST">
<input type="hidden" name="id" value="<? echo $row->id; ?>">
<tr>
<td valign="top"><b >Date<b></td>
<td><? echo $row->date; ?></td>
</tr>
<tr>
<td valign="top"><b ><? echo $row->home_team; ?></b></td>
<td><input size="5" name="home_shot s" value="<? echo
$row->home_shots; ?>"></td>
</tr>
<tr>
<td valign="top"><b ><? echo $row->away_team; ?></b></td>
<td><input size="5" name="away_shot s" value="<? echo
$row->away_shots; ?>"></td>
</tr>
<tr>
<td valign="top"><b >Match Completed</b></td>
<td><input type="checkbox" name="completed " value="Y"></td>
</tr>
<tr>
<td colspan=2><inpu t type="Submit" name="submit" value="Update"> </td>
</tr>
</form>
</table>
<?
}
// no result returned
// print graceful error message
else
{
echo "<font size=-1>That match could not be located in our
database.</font>";
}
}
// form submitted
// start processing it
else
{
// set up error list array
$errorList = array();
$count = 0;
// check for errors
// if none found...
if (sizeof($errorL ist) == 0)
{
// open database connection
$connection = mysql_connect($ host, $user, $pass) or die ("Unable to
connect!");
// select database
mysql_select_db ($db) or die ("Unable to select database!");
// generate and execute query
if ($home_shots > $away_shots) {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryhome = "UPDATE teams
SET played = played + 1,
won = won + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots',
points = points + 2 WHERE team = '$home_team'";
$queryaway = "UPDATE teams
SET played = played + 1,
lost = lost + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots' WHERE team = '$away_team'";
} elseif ($home_shots < $away_shots) {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryaway = "UPDATE teams
SET played = played + 1,
won = won + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots',
points = points + 2 WHERE team = '$away_team'";
$queryhome = "UPDATE teams
SET played = played + 1,
lost = lost + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots' WHERE team = '$home_team'";
} else {
$querymatches = "UPDATE matches
SET home_shots = '$home_shots',
away_shots = '$away_shots',
completed = '$completed' WHERE id = '$id'";
$queryhome = "UPDATE teams
SET played = played + 1,
drawn = drawn + 1,
sf = sf + '$home_shots',
sa = sa + '$away_shots',
points = points + 1 WHERE team = '$home_team'";
$queryaway = "UPDATE teams
SET played = played + 1,
drawn = drawn + 1,
sa = sa + '$home_shots',
sf = sf + '$away_shots',
points = points + 1 WHERE team = '$away_team'";
}
$result1 = mysql_query($qu erymatches) or die ("Error in query:
$query. " . mysql_error());
$result2 = mysql_query($qu eryhome) or die ("Error in query: $query.
" . mysql_error());
$result3 = mysql_query($qu eryaway) or die ("Error in query: $query.
" . mysql_error());
// print result
echo "<font size=-1>Update successful. <a href=list.php>G o back to
the main menu</a>.</font>";
// close database connection
mysql_close($co nnection);
}
else
{
// errors occurred
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($erro rList); $x++)
{
echo "<li>$error List[$x]";
}
echo "</ul></font>";
}
}
?>
<!-- standard page footer begins -->
<p>
<table width="100%" cellspacing="0" cellpadding="5" >
<tr>
<td align="center"> </td>
</tr>
</table>
<!-- standard page footer ends -->
</body>
</html>
Comment