Login   Register  
PHP Classes
elePHPant
Icontem

File: agolfhandicap.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of George Clarke  >  A Golf Handicap  >  agolfhandicap.php  >  Download  
File: agolfhandicap.php
Role: Example script
Content type: text/plain
Description: Example script for AGolfHandicap class
Class: A Golf Handicap
Record played golf games in a MySQL database
Author: By
Last change: Corrected filename in include statement.
Date: 8 years ago
Size: 1,875 bytes
 

Contents

Class file image Download
<?php
// This is an example script using the agolfhandicap class to record games played
// and calculate your golf handicap index.
// It is a multi user database and can keep track of games for different players.
// First enter your name or user name then the game information.
// This script really should be used with a user/password login system for security.
//
// Version 1.1.0: Added Edit and Delete for a record in the database. 
//
// ############ You must edit the username, password and database name further down.

include "class.agolfhandicap.php";
$gh=new agolfhandicap();

// ######### Edit the next line to put your MySQL username, password, and database name. ########
$gh->setupdb('username','password','databasename');

// Get the user name if submitted.
if($_POST['user']){
 
$user=$_POST['user'];
 
$gh->setuser($user);
}
if(
$_POST['delete']){          //delete the record
  
$id=$_POST['id'];
  
$gh->deleteGame($id);
}
if(
$_POST['edit']){           //edit the record
  
$id=$_POST['id'];
}
// If no user yet, ask for it.
if(!isset($_POST['user'])){
 print 
"<form name='usr' action='$PHP_SELF' method='POST'>";
 print 
"Enter your user name:<input type='text' name='user' size='20'>";
 print 
"<input type='hidden' name='hid' value='true'>";
 print 
"<input type='submit' value='Submit' name='submits'>";
 print 
"</form>";
}else{
// We have a username, so get new game data and display handicap and all games.
print "<h2>Golf Game Database and Handicap Calculator for $user</h2>\n";
$newgame=$gh->getnewgame($id);
$id=($_POST['edit']=="")? "":$id;
$gh->showform($id);
$hc=$gh->gethcap();
print (
$hc==0)?"<h3>You need at least 5 games for a handicap index.</h3>":"<h3>Handicap for $user is $hc</h3><br>";
// If you just want the data without displaying it, use next line.
//$al=$gh->getAll();
$gh->showall();
}
?>