Page 1 of 1

These errors, can someone tell me why?

Posted: Wed Feb 27, 2008 12:47 pm
by Monotoko
Hmm, i am getting the following:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gamersne/public_html/tgl/tests/gotest.php on line 43

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/gamersne/public_html/tgl/tests/gotest.php on line 55

Fatal error: SQL in /home/gamersne/public_html/tgl/tests/gotest.php on line 55

the first error is making me :banghead:
the second error i dont even want to touch
and the 3rd error, AAAAAAAAAAAARRRRRRRRRRRRRRRRRRRRRRRGHHHHHHHHHHHHHHHHHHHHHHHHHHHHh

Code: Select all

<?
 
$con = mysql_connect("localhost","xxxxxxxxxxxxx","xxxxxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("gamersne_mysys", $con);
 
echo "<table class='tborder' cellpadding='6' cellspacing='1' border='0' width='100%'
style='border-bottom-width:0px'>
<tr>
    <td class='tcat' width='100%'>
        <div align='center'>Members List</div></td>
    
</tr>
</table>
<table class='tborder' cellpadding='6' cellspacing='1' border='0' width='100%' align='center'>
<tr>
    <td class='alt1'><p align='center'><table border='1'>
<tr>
<td>Member</td>
<td>Gamers Level</td>
<td>Group</td>
<td>Clan</td>
<td>Joined</td>
<td>Posts</td>
<td>email</td>
</tr>
<tr>";
 
if (isset($_GET['pageno'])) 
{
 $pageno = $_GET['pageno'];
} 
else
{
 $pageno = 1;
}
 
$result = "SELECT * FROM members";
$query_data = mysql_num_rows($result);
$numrows = $query_data[0];
$rows_per_page = 15;
$lastpage      = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
   $pageno = 1;
} elseif ($pageno > $lastpage) {
   $pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM table $limit";
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
 
$name = $row['username'];
$lvl = $row['level'];
$group = $row['group'];
$email = $row['email'];
$clan = $row['clan'];
$posts = $row['posts'];
$joined = $row['joined'];
 
echo "<tr>
<td>$name</td>
<td>$lvl</td>
<td>$clan</td>
<td>$group</td>
<td>$joined</td>
<td>$posts</td>
<td>$email</td>
</tr>";
 
if ($pageno == 1) {
   echo " FIRST PREV ";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
   $prevpage = $pageno-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
 
echo " ( Page $pageno of $lastpage ) ";
 
if ($pageno == $lastpage) {
   echo " NEXT LAST ";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
?>

Re: These errors, can someone tell me why?

Posted: Wed Feb 27, 2008 2:00 pm
by liljester
you didnt query the data from mysql. replace line 42 with:

Code: Select all

$result = mysql_query("SELECT * FROM members;");
in line 42 you set $result to a string value (not a result resource).
in line 43 you try to use mysql_num_rows() on a string value.. wich throws your first error.

in line line 55 it looks like youre not using the right rescource identifier for your mysql connection, your code shows it to be $con, but you try to use $db in your mysql_query... wich throws your second error.

and trigger_error() is generating your third error, because of the second error.