Page 1 of 1

supplied argument is not a valid MySQL-Link resource

Posted: Thu Mar 01, 2012 1:50 pm
by chopficaro
says line 93 but ive even tried replacing the variable with the table name as part of the query string and it still give the same error^

Code: Select all

<!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 "\n";
				}
			}
		}
	}
	echo "
	</textarea>
  <br />
  <input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Submit\" />
 </form>

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

Re: supplied argument is not a valid MySQL-Link resource

Posted: Thu Mar 01, 2012 2:06 pm
by twinedev
Since when you copy the above code and place it into an editor, line 93 is "; can you tell us what line #93 is that you see.

I am guessing though it is the line that runs the mysql_query, in which you are passing it a second parameter of $connection The problem with that is you are inside a function and $connection is defined outside of it, so it is going to be NULL when you pass it to mysql_query.

You either need to declare that you are going to use that global variable via global $connection; somewhere in the function before you use it, or just leave it off, as if it is blank, mysql_* functions will use the last opened connection by default.

-Greg

Re: supplied argument is not a valid MySQL-Link resource

Posted: Thu Mar 01, 2012 3:34 pm
by chopficaro
greg u r the maaaaaaaaaan thank you so much