Jump to content

mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource


slickdeals

Recommended Posts

whats causing this error for me?

 

its on line 636 and 670

 

which I assume is while($row1 = mysql_fetch_assoc($get1)) {

and while($row = mysql_fetch_assoc($get)) {

 

but why?

 

function admin_ratesite() {

      echo "<center>";

      $get = mysql_query("SELECT url as surl, siterating as srating FROM wlddl_sites");

      if(isset($_REQUEST['ratesite'])){

      $rating = $_POST['srating'];

      $siteurl = $_POST['surl'];

      }

      echo '<b>Rate Site</b><br /><br />';

      echo '<form action="" method="post">';

      echo '<b>Site:</b> ';

      echo '<select name="surl" size="1">';

      echo '<option value="">- Select -</option>';

              while($row = mysql_fetch_assoc($get)) {

              echo '<option value="'.$row['surl'].'">'.$row['surl'].'</option>';

      }

      echo '</select>';

     

      echo ' <b>Rating:</b> ';

      echo '<select name="srating" size="1">';

      echo '<option value="">- Select -</option>';

      for($i=1;$i<=5;$i++) {$return = '<option value="'.$i.'">'.$i.'</option>'; echo $return;}

      echo '</select>';

      echo '<br /><br /><input type="submit" value="Rate Site!" name="ratesite" />';

      echo '</form>';

      if(isset($_REQUEST['ratesite'])){

      if(!$siteurl){

      echo "<br /><b>Error: Invalid Site</b>";

      } else if(!$rating) {

      echo "<br /><b>Error: Invalid Rating</b>";

      } else {

      mysql_query("UPDATE wlddl_sites SET siterating = '".mysql_real_escape_string($rating)."' WHERE url = '".mysql_real_escape_string($siteurl)."'");

      echo '<br /><b>'.$siteurl.' Has Successfully Been Rated!</b>';

      }

      }

      echo '<br /><hr /><br />';

 

      // Check Site Rating

      $get1 = mysql_query("SELECT url as surl, siterating as srating FROM wlddl_sites");

      if(isset($_REQUEST['checksrating'])){

      $siteurl = $_POST['surl'];

      $currentsrating = mysql_query("SELECT siterating, url FROM wlddl_sites WHERE url = '".mysql_real_escape_string($siteurl)."'");

      }

      echo '<b>Check Site Rating</b><br /><br />';

      echo '<form action="" method="post">';

      echo '<b>Site:</b> ';

      echo '<select name="surl" size="1">';

              while($row1 = mysql_fetch_assoc($get1)) {

              echo '<option value="'.$row1['surl'].'">'.$row1['surl'].'</option>';

      }

      echo '</select>';

      echo '<br /><br /><input type="submit" value="Check Site Rating" name="checksrating" />';

      echo '</form>';

      if(isset($_REQUEST['checksrating'])){

      while($row2 = mysql_fetch_assoc($currentsrating)) {

      echo "<br /><b>Site Rating For ".$row2['url'].":</b> ".$row2['siterating'];

      }

      }

      echo "</center>";

      }

He showed the error: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource  :D

 

It seems to me that you aren't connecting to the database with a valid connection. I don't know for sure, because I don't code like you are, but you should probably turn your database connection into a variable, if you haven't already.

 

As so:

$link = mysql_connect($host,$user,$pass) or die('Database Error: ' . mysql_error());

 

Then rewrite your mysql_query functions to connect directly, as so:

mysql_query("SELECT url as surl, siterating as srating FROM wlddl_sites", $link);

 

 

Also, remember, if you don't create the $link variable directly in the function, you'll have to make the variable a global within the function, as so:

function admin_ratesite() {

global $link;

 

 

Again, I'm not sure, because your coding style is a little weird to me. This is just something to try.  ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.