$caption Team1ScoreTeam2Score TABLE; } function connect() { $user = ""; $password = ""; $db = odbc_connect( 'PHPEG' , $user, $password ); if (!$db) die( "Error in odbc_connect" ); return $db; } function report($caption, $comment, $result) { $count = 0; // Can ask for number of rows returned, but // most drivers cannot supply this information while( odbc_fetch_row( $result) ) { if($count==0) tableheader($caption); $count++; $Team1 = odbc_result($result, "Name1"); $Score1 = odbc_result($result, "Score1"); $Team2 = odbc_result($result, "Name2"); $Score2 = odbc_result($result, "Score2"); print "$Team1$Score1$Team2$Score2"; } if($count>0) print ""; else print "

$comment

"; } function runtask($strings) { list($sqlstring, $caption, $comment) = $strings; $db = connect(); $result = odbc_exec( $db, $sqlstring); if (!$result) die( "Error in odbc_exec( no result returned ) " ); report($caption, $comment, $result); print ""; odbc_close( $db); } function homewins() { $home = array ( "select * from Teams where Score1 > Score2", "Home wins", "No home wins yet this season" ); runtask($home); } function awaywins() { $away = array ( "select * from Teams where Score1 < Score2", "Away wins", "No away wins yet this season" ); runtask($away); } function drawngames() { $drawn = array ( "select * from Teams where Score1 = Score2", "Drawn games", "No drawn games yet this season" ); runtask($drawn); } function listall() { $drawn = array ( "select * from Teams", "Season's matches", "Season has not started yet" ); runtask($drawn); } function doadd() { print <<
Enter result of match
Home teamScoreAway teamScore
ADDER; } function checkadd() { global $HTTP_POST_VARS; $msg = "Invalid or incomplete data; cannot add result"; $Team1 = $HTTP_POST_VARS["Team1"]; $Team2 = $HTTP_POST_VARS["Team2"]; $Score1 = $HTTP_POST_VARS["Score1"]; $Score2 = $HTTP_POST_VARS["Score2"]; if(!(isset($Team1) && isset($Team2) && isset($Score1) && isset($Score2))) die($msg); $Score1 = (integer) $Score1; $Score2 = (integer) $Score2; $db = connect(); $sql_string = "insert into Teams Values( '$Team1', '$Team2', $Score1, $Score2 )"; $result = odbc_exec($db, $sql_string); if(!$result) die("Failed to update database"); print <<Result added to database. ADDED; odbc_close($db); } function mainform() { print <<Soccer league keeper You may review the existing contents of the database or add data.
Add data
List all data
List drawn games
List home wins
List away wins
FORMSTUFF; } if(!empty($HTTP_POST_VARS)) { $choice = $HTTP_POST_VARS["choice"]; if($choice=="home") { homewins(); exit(); } elseif($choice=="away") { awaywins(); exit(); } elseif($choice=="draw") { drawngames(); exit(); } elseif($choice=="list") { listall(); exit(); } elseif($choice=="add") { doadd(); exit(); } elseif(!isset($choice)) { checkadd(); exit(); } } else { mainform(); exit(); } ?>