Jump to content

Recommended Posts

Hi guys, I need some help with my php coding. I want to create a soccer league generator where you can add result and when you submit the result the league table will automaticly refresh with new data of points, goals scored, goals conceded, goal difference, games won, games lost, games draw and games played of a player. I need help with adding result to database and then displaying in to league table. Can you gave me some advice of the best aproach to do that!

Link to comment
https://forums.phpfreaks.com/topic/255605-league-table-generator/
Share on other sites

This is add_result.php

<?php

session_start();

include_once "connect_to_database.php";

$league_id = "";
$member_id = "";
$member_firstname = "";
$member_lastname = "";
$member_nickname = "";
$member_email = "";
$error_message = "";

if(isset($_GET['league_id']))
{
$league_id = preg_replace('#[^0-9]#i', '', $_GET['league_id']);
}
else if (isset($_SESSION['league_id']))
{
$league_id = $_SESSION['league_id'];
}
else
{
header("location: index.php");
exit();
}

$league_id = preg_replace('#[^0-9]#i', '', $league_id);

$query = mysql_query ("SELECT * FROM league WHERE league_id='$league_id' LIMIT 1");
$check_exist_acc = mysql_num_rows($query);
if($check_exist_acc==0)
{
	header("location: index.php?msg=league_does_not_exist");
	exit();
}
	while($row = mysql_fetch_array($query))
	{
		$league_id = $row['league_id'];
		$league_name = $row['league_name'];
	}

////////////////////////////////////ADD RESULT///////////////////////////////////////////

////////////////////////////////////END ADD RESULT///////////////////////////////////////		
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PES League</title>
</head>

<body>
<a href="exit.php">Exit</a>
<a href="add_player.php">Add Player</a>
<a href="league.php">League Table</a>
<br />
<br />
<table id="add_result" border="1" cellpadding="3">
<form id="add_result" method="post" action="add_result.php">
    	<tr>
        	<td>Add Result</td>
        </tr>
        <tr>
        	<td><input id="home_player" name="home_player" type="text" maxlength="25" /></td>
        	<td><input id="home_score" name="home_score" type="text" maxlength="2" size="2" /></td>
        	<td><strong>:</strong></td>
        	<td><input id="away_score" name="away_score" type="text" maxlength="2" size="2" /></td>
        	<td><input id="away_player" name="away_player" type="text" maxlength="25"  /></td>
        </tr>
        <tr>
        	<td><input id="submit_score" name="submit_score" type="submit" value="Submit" /></td>
            <td><input id="update_submit_score" name="update_submit_score" type="hidden" value="updSubmit" /></td>
        </tr>
    </form>
</table>
<br />
<br />
</body>
</html>

 

 

 

And  I want to display the results in the league table on this page league.php

<?php

session_start();

include_once "connect_to_database.php";

$league_id = "";
$member_id = "";
$member_firstname = "";
$member_lastname = "";
$member_nickname = "";
$member_email = "";
$error_message = "";

if(isset($_GET['league_id']))
{
$league_id = preg_replace('#[^0-9]#i', '', $_GET['league_id']);
}
else if (isset($_SESSION['league_id']))
{
$league_id = $_SESSION['league_id'];
}
else
{
header("location: index.php");
exit();
}

$league_id = preg_replace('#[^0-9]#i', '', $league_id);

$query = mysql_query ("SELECT * FROM league WHERE league_id='$league_id' LIMIT 1");
$check_exist_acc = mysql_num_rows($query);
if($check_exist_acc==0)
{
	header("location: index.php?msg=league_does_not_exist");
	exit();
}
	while($row = mysql_fetch_array($query))
	{
		$league_id = $row['league_id'];
		$league_name = $row['league_name'];
	}

////////////////////////////////////ADD MEMBER TO TABLE//////////////////////////////////
$member_sql = ("SELECT member_id, member_nickname, games_played, games_won, games_draw, games_lost, goals_scored, goals_conceded, goal_difference, points FROM league_members ORDER BY points desc");
$member_query = mysql_query($member_sql) or die (mysql_error());
$result_member = mysql_fetch_assoc($member_query);
////////////////////////////////////END ADD MEMBER TO TABLE//////////////////////////////

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PES League</title>
</head>

<body>
<a href="exit.php">Exit</a>
<a href="add_player.php">Add Player</a>
<a href="add_result.php">Add Result</a>
<br />
<br />
<table id="league_table" border="1" cellpadding="3" cellspacing="1">
<tr>
    	<td>Player</td>
        <td>Games Played</td>
        <td>Won</td>
        <td>Drawn</td>
        <td>Lost</td>
        <td>Goal Scored</td>
        <td>Goal Conceded</td>
        <td>Goal Difference</td>
        <td>Points</td>
    </tr>
    <?php do { ?>
    <tr>
    	<td><?php echo $result_member['member_nickname'];?></td>
        <td><?php echo $result_member['games_played'];?></td>    
    	<td><?php echo $result_member['games_won'];?></td>    
    	<td><?php echo $result_member['games_draw'];?></td>    
    	<td><?php echo $result_member['games_lost'];?></td>    
    	<td><?php echo $result_member['goals_scored'];?></td>
    	<td><?php echo $result_member['goals_conceded'];?></td>                
    	<td><?php echo $result_member['goal_difference'];?></td>    
    	<td><?php echo $result_member['points'];?></td>            
    </tr>
    <?php } while($result_member = mysql_fetch_assoc($member_query)); ?>
</table>
<br />
<br />
</body>
</html>

 

 

This is for add a player to a table:

<?php

session_start();

include_once "connect_to_database.php";

error_reporting (E_ALL ^ E_NOTICE);

$league_id = "";

if(isset($_GET['league_id']))
{
$league_id = preg_replace('#[^0-9]#i', '', $_GET['league_id']);
}
else if (isset($_SESSION['league_id']))
{
$league_id = $_SESSION['league_id'];
}
else
{
header("location: index.php");
exit();
}

$league_id = preg_replace('#[^0-9]#i', '', $league_id);

$query = mysql_query ("SELECT * FROM league WHERE league_id='$league_id' LIMIT 1");
$check_exist_acc = mysql_num_rows($query);
if($check_exist_acc==0)
{
	header("location: index.php?msg=league_does_not_exist");
	exit();
}
	while($row = mysql_fetch_array($query))
	{
		$league_id = $row['league_id'];
		$league_name = $row['league_name'];
	}

////////////////////////////////////CREATE PLAYER////////////////////////////////////////////
$member_id = "";
$member_firstname = "";
$member_lastname = "";
$member_nickname = "";
$error_message = "";
if(isset($_POST['member_firstname']))
{
//Filter everything
$member_firstname = preg_replace('#[^A-Za-z]#i', '', $_POST['member_firstname']);
$member_lastname = preg_replace('#[^A-Za-z]#i', '', $_POST['member_lastname']);
$member_nickname = preg_replace('#[^A-Za-z0-9]#i', '', $_POST['member_nickname']);

$member_firstname = stripslashes($member_firstname);
$member_lastname = stripslashes($member_lastname);
$member_nickname = stripslashes($member_nickname);

$member_firstname = strip_tags($member_firstname);
$member_lastname = strip_tags($member_lastname);
$member_nickname = strip_tags($member_nickname);

//Error missing data
if((!$member_firstname) || (!$member_lastname) || (!$member_nickname))
{
	$error_message = "You did not fill the following information!!!!<br />";

	if(!$member_firstname)
	{
		$error_message .= "* Missing First Name!<br />";
	}
	if(!$member_lastname)
	{
		$error_message .= "* Missing Last Name!<br />";
	}
	if(!$member_nickname)
	{
		$error_message .= "* Missing Nick Name!<br />";
	}

} 
else
{
	include_once "connect_to_database.php";

	$member_firstname = mysql_real_escape_string($member_firstname);
	$member_lastname = mysql_real_escape_string($member_lastname);
	$member_nickname = mysql_real_escape_string($member_nickname);

	$query = mysql_query ("INSERT INTO league_members (member_firstname, member_lastname, member_nickname) VALUES ('$member_firstname', '$member_lastname', '$member_nickname')") or die (mysql_error());

	$member_id = mysql_insert_id();

	$error_message = "Successfully created!";
}
}
else
{
$member_firstname = "";
$member_lastname = "";
$member_nickname = "";
$error_message = "";
}
////////////////////////////////////////////////////END CREATE PLAYER/////////////////////////////////////7/////////		
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PES League</title>
<script src="js/jquery-1.4.2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript"> 
$(document).ready(function() {
$("#member_nickname").blur(function() {
	$("#nicknameresponse").removeClass().text('Checking Nick Name...').fadeIn(1000);
	$.post("check_nickname.php",{ member_nickname:$(this).val() } ,function(data) {
	  	$("#nicknameresponse").fadeTo(200,0.1,function() { 
		  $(this).html(data).fadeTo(900,1);	
		});
        });
});
});
function toggleSlideBox(x) {
	if ($('#'+x).is(":hidden")) {
		$('#'+x).slideDown(300);
	} else {
		$('#'+x).slideUp(300);
	}
}
</script>
</head>
<body>
<a href="league.php">League Table</a>
<br />
<br />
<br />
<br />
<br />
<br />
<?php echo $error_message ?>
<table>
<form id="create_player" name="create_player" method="post" action="add_player.php" enctype="multipart/form-data">
    	<tr>
        	<td>Add Player</td>
        <tr>
        <tr>
        	<td>First Name:</td>
        	<td><input id="member_firstname" name="member_firstname" type="text" maxlength="25" /></td>
        </tr>
        <tr>
        	<td>Last Name:</td>    
            <td><input id="member_lastname" name="member_lastname" type="text" maxlength="25" /></td>
        </tr>
        <tr>
        	<td>Nick Name:</td>    
        	<td><input id="member_nickname" name="member_nickname" type="text" maxlength="25" /></td>
            <td><span id="nicknameresponse"></span></td>
        </tr>
        <tr>
        	<td><input id="submit" type="submit" value="Create" /></td>
        </tr>
    </form>
</table>
</body>
</html>

 

edit (KP): please use code tags next time

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.