Jump to content

Recommended Posts

a little insight into this i am currently a director of a group of bg  tournaments that are played onlines and ran from hosts i managed to get  a person to help ke with the php coding and payed no attention to the database otherwise id have seen this problem coming sooner 

The structure

3 databases points  tourney report and emails  the  problem is is in all the code i need to keep recoords from previous months and  cant keep it  updating each month so  that at end of this month  i change from july to august in scripts and will then only show august points now the  problems i know where they are but i have no idea where to even start

 

problem 1 points  are being updated in database and not added  between multiple  entries ef  i  have me with 32 points  if i add in another entry of 12 points  it will still show as 1 entry  now what i understand i need to do is  to  have 2 entrys and have the php script add them where the conditions are met si that if i call on august it will only add the  players points  that were added in august

 

 

 

and 2nd problem is i need to have the script reply with post updated successfully  upon a successful post here is the php code i have

 

<style type="text/css">
<!--
Table {border-collapse:collapse; border-color:#000000; border-width:2px; cellpadding:3px;}
Table THEAD TD{background-color:#00FFFF; color:#FF0000; font-weight:bold; font-size:larger;; padding:3px; border:1px solid black}
Table TR TD {padding:3px;border: 1px solid black}
-->
</style>
<?
//print_r($_SERVER);
	$sn = $_SERVER['PHP_SELF'];
	mysql_connect(null, "havensd1_tourn", "z(:wI,VL91SL"); //Put login and password for mysql here. Replace null with mysql server address if provided by host.

	mysql_select_db("havensd1_tournaments") or die(mysql_error());//Put databasename here
	mysql_query("create table if not exists tourne_report (Host TEXT, Date_Time DATETIME, PlayersCount INT, Winner TEXT, WinnerEmail TEXT, SecondPlace TEXT, SecondEmail TEXT, ThirdPlace TEXT, ThirdEmail TEXT, ThirdPlace2 TEXT, ThirdEmail2 TEXT)");
	mysql_query("create table if not exists emails (PlayerName char(30) key not null, email TEXT)");
	mysql_query("create table if not exists points (PlayerName char(30) key not null, Points INT, Date_Time DateTime)");

if (isset ($_GET["act"]))
{
	if ($_GET["act"] == "erase")
	{
		mysql_query("drop table tourne_report");
		mysql_query("drop table emails");
		mysql_query("drop table points");
		mysql_query("create table if not exists tourne_report (Host TEXT, Date_Time DATETIME, PlayersCount INT, Winner TEXT, WinnerEmail TEXT, SecondPlace TEXT, SecondEmail TEXT, ThirdPlace TEXT, ThirdEmail TEXT, ThirdPlace2 TEXT, ThirdEmail2 TEXT)");
		mysql_query("create table if not exists emails (PlayerName char(30) key not null, email TEXT)");
		mysql_query("create table if not exists points (PlayerName char(30) key not null, Points INT, Date_Time DateTime)");

	}
	if ($_GET["act"] == "points")
	{
		?>
		<table>
		<thead>
		<td>Place</td>
		<td>PlayerName</td>
		<td>Points</td>
		</thead>
		<?
			$i = 0;
			$d = date("Y-m-");
			$d .= "01 00:00:00";
			//$d = preg_replace("/-(\d+) /", "-01 ", $d);
			echo("Extracting data since $d<br/>");

			$r = mysql_query("select * from points where Date_Time > '$d' order by Points DESC");
			while ($v = mysql_fetch_assoc($r))
			{
				++$i;
				echo("<tr><td>$i</td><td>${v["PlayerName"]}</td><td>${v["Points"]}</td></tr>\n");
			}

		?>
		</table>
		<?//<a href="<?echo ($sn);?><?//">Back</a>?>
		<?
		exit();

	}
	if ($_GET["act"] == "emails")
	{
		?>
		<table>
		<thead>
		<td>PlayerName</td>
		<td>EMail</td>
		</thead>
		<?

			$r = mysql_query("select * from emails order by PlayerName ASC");
			while ($v = mysql_fetch_assoc($r))
			{
				if ($v["PlayerName"] != "")
					echo("<tr><td>${v["PlayerName"]}</td><td>${v["email"]}</td></tr>\n");
			}

		?>
		</table>
		<?//<a href="<?echo ($sn);?><?//">Back</a>?>
		<?
		exit();

	}
	if ($_GET["act"] == "toc")
	{
			$d = date("Y-m-");
			$d .= "01 00:00:00";
			//$d = preg_replace("/-(\d+) /", "-01 ", $d);
			echo("Extracting data since $d<br/>");

		?>
		<h2>TOC:</h2>
		<table>
		<tr>
		<?
			$i = 0;
			$all = array();
			$r = mysql_query("select * from tourne_report where Date_Time > '$d' order by Date_Time DESC");
			while ($v = mysql_fetch_assoc($r))
			{

			if ($v["Winner"] != "")
				{
					$all[] = $v["Winner"];
				}
			if ($v["SecondPlace"] != "")
				{
					$all[] = $v["SecondPlace"];
				}						
			if ($v["ThirdPlace"] != "")
				{
					$all[] = $v["ThirdPlace"];
				}						
			if ($v["ThirdPlace2"] != "")
				{
					$all[] = $v["ThirdPlace2"];
				}						
			}
			sort($all,SORT_STRING);
			$all = array_unique($all);
			foreach ($all as $k)
			{
					echo("<td>$k</td>");
					$i++;
					if ($i == 3)
					{
						echo("</tr><tr>");
						$i = 0;
					}

			}

			while ($i != 3 && $i!=0)
			{
				echo("<td></td>");
				++$i;
			}


		?>
		</tr>
		</table>			
		<?//<a href="<?echo ($sn);?><?//">Back</a>?>
		<?
		exit();

	}
	if ($_GET["act"] == "months")
	{
		?>
		<table>
		<thead>
		<td>Host</td>
		<!--<td>Nick</td> -->
		<td>Date_Time</td>
		<td>Winner</td>
		<td>#of players</td>
		</thead>
		<?
			$d = date("Y-m-");
			$d .= "01 00:00:00";
			//$d = preg_replace("/-(\d+) /", "-01 ", $d);
			echo("Extracting data since $d<br/>");
			$r = mysql_query("select * from tourne_report where Date_Time>'$d' order by Date_Time DESC");
			while ($v = mysql_fetch_assoc($r))
			{
				echo("<tr><td>${v["Host"]}</td><td>${v["Date_Time"]}</td><td>${v["Winner"]}</td><td>${v["PlayersCount"]}</td></tr>\n");
			}

		?>
		</table>
		<?//<a href="<?echo ($sn);?><?//">Back</a>?>
		<?
		exit();

	}

}
function not_2($var)
{
	/*echo("<br><br>");
	print_r($var);*/

	if (count($var) != 2) return false;
	else return true;
}
if (isset($_POST["asfile"]))
{
	//print_r($_POST);
	echo("<br>");
	$file = $_POST["file"];
	$points = strstr($file, "START POINTS");
	//print_r($points);
	$_POST["Points"] = $points;
	$file = explode("\n", $file);
	foreach ($file as $k)
	{
		$lines[] = explode(":", $k, 2);
	}
	$lines = array_filter($lines, "not_2");
	//print_r($lines);
	foreach ($lines as $value) 
	{
		$value[0] = trim($value[0]);
		$value[1] = trim($value[1]);
		switch (strtolower($value[0])) {
				case "date": $_POST["At"] = $value[1];
					break;
				case "scheduled start": $_POST["AtTime"] = $value[1];
					break;
				case "host": $_POST["Host"] = $value[1];
					break;

				case "number of players": $_POST["PC"] = $value[1];
					break;						
				case "1st place": $_POST["p1"] = $value[1];
					break;						
				case "1st place email": $_POST["e1"] = $value[1];
					break;												
				case "2nd place": $_POST["p2"] = $value[1];
					break;						
				case "2nd place email": $_POST["e2"] = $value[1];
					break;							
				case "3rd place":
						if (isset($_POST["p3"]))
						{
							$_POST["p23"] = $value[1];
						}
						else 
						{
							$_POST["p3"] = $value[1];
						}
					break;						
				case "3rd place email": 				
						if (isset($_POST["e3"])) $_POST["e23"] = $value[1];
						else $_POST["e3"] = $value[1];
					break;																													
				default:
					break;
			}	
			$_POST["send"] = 1;




	}
					$vars = array("At", "AtTime", "Host", "PC", "p1", "e1", "p2", "e2", "p3", "e3", "p23", "e23");
			foreach ($vars as $k)
			{
				if (!isset($_POST[$k]))
					$_POST[$k] = "";
			}

/*						echo("Here:<br>");
	print_r($_POST);		
			echo("<br>");*/

}
if (isset ($_POST["send"]))
{
	foreach ($_POST as $k=>$v)
	{
		$$k = $v;
	}
	//$d = explode(" ", $At);
	$dat = explode ("/",$At);
	if (count($dat)!=3) die("Bad date format.");
	$tim = explode(":", $AtTime);
	if (count($tim)<2) die("Bad time format.");
	$plus = 0;
	if (strstr(strtoupper($tim[1]), "PM"))
	{
		$plus = 12;
	}
	$h = $tim[0];
	$m = explode(" ", $tim[1]);
	$m = $m[0];
	$h+= $plus;
	$At = "${dat[2]}-${dat[0]}-${dat[1]} $h:$m:00";
//		echo("$At");
//		$d = strtotime($At);
	//$At = date("Y-m-d H:i:s", $d);
	//echo("At: $At<br/>");
	//echo("At: $At<br/>");
	mysql_query("insert into tourne_report values ('$Host', '$At', $PC, '$p1', '$e1', '$p2', '$e2', '$p3', '$e3', '$p23', '$e23')") or die (mysql_error());
	$Points = explode("\n", $Points);
	mysql_query("insert ignore into emails values ('$p1', '$e1'),('$p2', '$e2'), ('$p3', '$e3'), ('$p23', '$e23')") or die (mysql_error());
	foreach ($Points as $v)
	{
		if ($v == "") continue;
		$v = explode (" ", $v);
		if (count($v) != 2)
			die("Incorrect values in POINTS input (check spaces!)<br>");
		if (strstr(strtolower($v[1]), 'points')) continue;

		$r = mysql_query("insert into points values ('${v[0]}', ${v[1]}, '$At') on duplicate key update Points = Points + ${v[1]}");
		if (!$r) die (mysql_error());
	}
	//print_r($Points);
}
?>
<!--
<form method="POST" action="<?echo ($sn);?>">
<table>
<tr>
<td>
Host:</td> <td><input type = "text" name = "Host" /></td><td>Host name</td>
</tr>
<!--<tr>
<td>

Nick:</td> <td> <input type = "text" name = "Nick" /></td><td>Nick //What is it?</td> -->
<!--
<tr>
<td>

Date: </td> <td><input type = "text" name = "At" /></td><td>In "MM/DD/YYYY" format</td>
<tr>
<td>

Time: </td> <td><input type = "text" name = "AtTime" /></td><td>In "HH:MM A" format where A is either AM or PM</td>
<tr>
<td>

PlayersCount:</td> <td> <input type = "text" name = "PC" /></td><td>Integer value</td>
<tr>
<td>

Winner:</td> <td> <input type = "text" name = "p1" /></td><td>Winner name</td>
<tr>
<td>

Winner's email: </td> <td><input type = "text" name = "e1" /></td><td>Winner email</td>
<tr>
<td>

2nd place:</td> <td> <input type = "text" name = "p2" /></td><td>2nd name</td>
<tr>
<td>

2nd place email:</td> <td> <input type = "text" name = "e2" /></td><td>2nd email</td>
<tr>
<td>

3rd place:</td> <td> <input type = "text" name = "p3" /></td><td>3rd name</td>
<tr>
<td>

3rd place email:</td> <td> <input type = "text" name = "e3" /></td><td>3rd email</td>
<tr>
<td>

2_3rd place:</td> <td> <input type = "text" name = "p23" /></td><td>Second third place :-)</td>
<tr>
<td>

2_3rd place email:</td> <td> <input type = "text" name = "e23" /></td><td>Second third place email</td>
</table>
Points:<br>
<textarea name="Points" cols="30" rows="7"></textarea>
<br/>
<input type = "submit" name="send" value="Send results"/>
</form>
-->
<img src = "/Posting%20pOints.jpg" /> 
<form method="POST" action="<?echo ($sn);?>">
File contents:<br/>
<textarea name="file" cols="100" rows="20"></textarea><br/>
<input type="submit" name="asfile" value="Send a file" />
</form>
<a href = "<?echo ($sn);?>?act=points">Points</a><br>
<a href = "<?echo ($sn);?>?act=toc">Toc qualifiers</a><br>
<a href = "<?echo ($sn);?>?act=emails">Emails</a><br>
<a href = "<?echo ($sn);?>?act=months">Monthly report</a><br>
<?//<a href = "<?echo ($sn);?><?//?act=erase">ERASE</a><br>
?>

Link to comment
https://forums.phpfreaks.com/topic/167823-php-code-need-help-to-tweak/
Share on other sites

mysql_query("create table if not exists tourne_report (Host TEXT, Date_Time DATETIME, PlayersCount INT, Winner TEXT, WinnerEmail TEXT, SecondPlace TEXT, SecondEmail TEXT, ThirdPlace TEXT, ThirdEmail TEXT, ThirdPlace2 TEXT, ThirdEmail2 TEXT)");
      mysql_query("create table if not exists emails (PlayerName char(30) key not null, email TEXT)");
      mysql_query("create table if not exists points (PlayerName char(30) key not null, Points INT, Date_Time DateTime)");

 

These only need to be executed once (not on each and every request), put it in a separate file called install.php or something.

 

mysql_connect(null, "havensd1_tourn", "z(:wI,VL91SL");

 

This needs an actual value not null and store the value it returns you need it.

 

mysql_select_db("havensd1_tournaments") or die(mysql_error());//Put databasename here

 

Remove 'or die()' your visitors don't know what 'You have an error in your sql syntax near ..' means.

 

mysql_query("drop table tourne_report");
         mysql_query("drop table emails");
         mysql_query("drop table points");
         mysql_query("create table if not exists tourne_report (Host TEXT, Date_Time DATETIME, PlayersCount INT, Winner TEXT, WinnerEmail TEXT, SecondPlace TEXT, SecondEmail TEXT, ThirdPlace TEXT, ThirdEmail TEXT, ThirdPlace2 TEXT, ThirdEmail2 TEXT)");
         mysql_query("create table if not exists emails (PlayerName char(30) key not null, email TEXT)");
         mysql_query("create table if not exists points (PlayerName char(30) key not null, Points INT, Date_Time DateTime)");

 

He never heard of truncate, did he?

 

This script is seriously FUBAR (F***ed Up Beyond All Repair) Who the hell wrote this?

 

 

i was running tight on time and  payed for it to be done by a guy on  getafreelancer i  did it out of my pocket  to help the tournament hosts i cant afford to pay anyone to update it so i have to figure it out ots npn p[[rpfot website and  i have no clue where to even start but thank you for that help

 

i was running tight on time and  payed for it to be done by a guy on  getafreelancer i  did it out of my pocket  to help the tournament hosts i cant afford to pay anyone to update it so i have to figure it out ots npn p[[rpfot website and  i have no clue where to even start but thank you for that help

 

 

I am not entirely sure how getafreelancer works but I would file a complaint or ask my money back. Even if you modify this code you still would have a serious security problem not to mention a database overhead (drop table, create table).

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.