SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Code:
    <!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>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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:

    PHP Code:
    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.

  3. #3
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •