Supplied argument is not a valid MySQL-Link resource in

THERES NOTHING WRONG WITH MY QUERY!!!
why am i getting this error???
im so confused…
says line 93 but ive even replaced the variable with the real table name as part of the query string with no change in the error

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="/css/mw3dailymedia.css?a=<%=now%>" />
</head>
<body>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<img src="background.jpg" alt="background image" id="fixed" />

<div id="login">
<div class="fb-like" data-href="http://www.youtube.com/watch?v=mA2aTK2JQRc" data-send="true" data-width="120" data-show-faces="true"></div>
<br/>
<p>
<a href="http://www.youtube.com/subscription_center?add_user=williebeemin22" target="_blank"><img src="/subscribe.gif" border="0" alt="Photobucket"></a>
<br/>
<a href="/">home</a>
<br/>
<a href="/">login/register</a>
</p>
</div>
<div id="content">
<div id="admin">
<?php

	// redifine variables for different server
	require_once "textprep.php";
	require_once "mysqlconfig.php";
	
	// connect to database
	$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
	if (!$connection)
	{
		die("Database connection failed: " . mysql_error());
	}

	// select database
	$db_select = mysql_select_db(DB_NAME,$connection);
	if (!$db_select)
	{
		die("Database selection failed: " . mysql_error());
	}

	//user's header
	
echo  "<img src=\\"2.gif\\" alt=\\"emblem\\" />";

//content
// sections EDIT, TWIXTOR, GAMEPLAY, GLITCHES/CHEATS, MONTAGES, SHORT CLIPS/FAILS, NEWS, TOP3, TH3RRC
mysqlTableAdmin("edit");
mysqlTableAdmin("twixtor");
mysqlTableAdmin("gameplay");
mysqlTableAdmin("glitch");
mysqlTableAdmin("montage");
mysqlTableAdmin("short");
mysqlTableAdmin("news");
mysqlTableAdmin("top3");
mysqlTableAdmin("th3rrc");

//functions
function mysqlTableAdmin($mysqlTableName)
{
	echo "
<h1>add to ".$mysqlTableName."</h1>
 <form action=\\"".$mysqlTableName."/post.php\\" method=\\"post\\">
  <label for=\\"title\\">Title</label>
  <input type=\\"text\\" name=\\"title\\" id=\\"title\\" />
  <br />
  <label for=\\"text\\">Description</label>
  <input type=\\"text\\" name=\\"text\\" id=\\"text\\" />
  <br />
  <label for=\\"link\\">Youtube Code</label>
  <input type=\\"text\\" name=\\"link\\" id=\\"link\\" />
  <br />
  <input type=\\"submit\\" name=\\"submit\\" id=\\"submit\\" value=\\"Submit\\" />
 </form>
 <img src=\\"2.gif\\" alt=\\"emblem\\" />
<h1>rearrange or delete ".$mysqlTableName."</h1>
<form action=\\"".$mysqlTableName."/swaper.php\\" method=\\"post\\">
  <label for=\\"text\\">Text</label>
  <br />
  <textarea rows=\\"10\\" cols=\\"50\\" name=\\"text\\" id=\\"text\\">
  ";


	// get table
	$result = mysql_query("SELECT * FROM ".$mysqlTableName, $connection);
	if (!$result)
	{
		die("Database query failed: " . mysql_error());
	}
	$i=0;
	
	// display table
	while ($row = mysql_fetch_array($result))
	{
		$rank[$i]=$row["rank"];
		$name[$i]=$row["title"];
		$i++;
	}
	
	//make a list of ranks to check for
	for($j=0;$j<$i;$j++)
	{
		$rankList[$j]=$j+1;
	}	
	
	//check the list
	for($j=0;$j<$i;$j++)
	{
		for($k=0;$k<$i;$k++)
		{
			if($rankList[$j]==$rank[$k])
			{
				echo $rank[$k]." ".$name[$k];
				if ($j<($i-1))
				{
					echo "\
";
				}
			}
		}
	}
	echo "
	</textarea>
  <br />
  <input type=\\"submit\\" name=\\"submit\\" id=\\"submit\\" value=\\"Submit\\" />
 </form>

 <img src=\\"2.gif\\" alt=\\"emblem\\" />
 ";
 }
?>
 </div>
 </div>
</body>
</html>

The reason why it’s not working is because $connection is not in the same scope as your function, to fix it see the below:

function mysqlTableAdmin($mysqlTableName)
{
    global $connection;

You may already know but just to revise it; When using variables that need to be used within a local scope they need to be declared as part of the local scope using the global definition, you can also use the superglobal called $GLOBALS which is fine to use.

I agree with chris.upjohn, it’s definitely a scope problem, as the function doenst known what $connection is, so you will need to global it or pass it into the function as an argument.