php enter results to db amd pull data from the db

ok i have a code not very secure code but the only one with access to the page is me so security wise im not overly concerned till i can pay someone to do a code that will work
here is a basic outline of what the code is supposed to do is take from this
Nojoks’s Tourney Bracket Tool Version 1.2.1.84
Tournament: DeepBlueSea
Date: 11/22/2013
Day: Friday
Scheduled Start: 9:30
Actual Start: 5:32:28 PM
Closed: 5:44:08 PM
Host: justme67 ()
Number of Players: 16
1st place: nurith
1st place email:
2nd place: TheAfterlife
2nd place email:
3rd place: Cristina
3rd place email:
3rd place: Morty
3rd place email:
START POINTS
BOMBER 1
ADG_ISABELLE 1
EU_IT_mirejo 1
EU_IT_petra 1
Sallyforth 1
TM7_CharrM5_ 1
UBG_Bonny 1
ziko_14 1
blackred 4
UBG_DBLEDAREYA 4
UBG_DJ_Cuber 4
UBG_Mila 4
Cristina 17
Morty 17
TheAfterlife 30
nurith 42
STOP POINTS
and insert intop the 3 tables
i have 3 tables
table1 - emails present columns (player name, email) would like to add id so that it can be the primary
data is pulled from whats in red

table 2 points (Date time) pulled from the input i am placing below , player name, points)would like to add id so that it can be the primary pulled from orange text ** players names may duplicate as they play in more then one tour but can not be update as each month the points get reset so each player needs a new entry everytime they are entered

table 3
tourne report
gives all the section above start poiints in a table including first 2nd 3rd place time of tour date of tour and host name and number of players

now this is the code that i have and have got it semi functional except i have a couple issues with it and will explain about them after the code

[php]

<?php //print_r($_SERVER); $sn = $_SERVER['PHP_SELF']; mysql_connect(localhost, "dbs", "ap6Ju4m:ekQh"); //Put login and password for mysql here. Replace null with mysql server address if provided by host. mysql_select_db("dbs_forms") 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:
”);

	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);

}

?>

File contents:


?act=points">Points

?act=toc">Toc qualifiers

?act=emails">Emails

?act=months">Monthly report

<?//<?//?act=erase">ERASE

?>[/php]

ok the issues are a the player name is listed as primary therefore wont allow me to enter duplicates so i tried entering an id in database but then it responds invalid number of colums
issue 2 is the toc list is not alphabetical and is spitting in 3 columns i would like one long list

and finally i need to find out where to change the dates or add lines in to tell the code that when pulling data to only pull between 2 set dates i need to do one for the points page which will be current month and one for the toc page which will be previous month
i hope i have explained adequately any extra info i will give

and before someone says why dont you pay for someone to do it the answer is this i get no pay no nothing for the site or hosting for the backgammon group but to some this is all that they can do ie shut ins or people who have medical issues so it is completely volunteer based why i have done the best i can with what i have any help will be greatly appreciated

Sponsor our Newsletter | Privacy Policy | Terms of Service