Jump to content

mysql_num_rows error


AsiaUnderworld

Recommended Posts

I've moved my code to a new server, and ive now got these errors

 

Warning mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/niccaman/public_html/checkuser.php on line 42

 

Warning mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/niccaman/public_html/checkuser.php on line 42

 

Warning mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/niccaman/public_html/checkuser.php on line 57

 

Warning mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/niccaman/public_html/checkuser.php on line 57

 

Warning cannot modify header information - headers already sent by (output started at /home/niccaman/public_html/checkuser.php:42) in home/niccaman/public_html/checkuser.php on line 24

 

 

Whats up with this?

 

Here are the lines around 42:

 

37  global $con;

38  $q = "SELECT ID FROM userinfo WHERE username = '$user'";

39  $result = mysql_query($q, $con);

40  $result = mysql_fetch_array($result) o die ('error: ' .mysql_error());

41  $i = 0;

42  while ($i <= mysql_num_rows($result))

43  {

44    $r = $r . $result[$i];

45  $i++;

46  }

47

48  return $r;

49  }

 

 

help would be great

Link to comment
https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/
Share on other sites

Is there any way for you to check the logs from your old server? You might have moved to a server that's displaying the warnings in the php.ini instead of logging them.

 

If your page is still displaying with the warnings that I would look that the display_errors setting on the php.ini and then restart apache

Link to comment
https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771479
Share on other sites

Try this:

 

 

37   global $con;
38   $q = "SELECT ID FROM userinfo WHERE username = '".$user."' ";
39   $result = mysql_query($q, $con);
40   $result = mysql_fetch_array($result) or die ('error: ' .mysql_error());
41   $i = 0;
42   while ($i <= mysql_num_rows($result))
43   {
44    $r = $r . $result[$i];
45   $i++;
46   }
47
48   return $r;
49  }

Link to comment
https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771483
Share on other sites

Change:

$result = mysql_query($q, $con);

to

$result = mysql_query($q, $con) or die(mysql_error());

 

You should put the or die on the query, not the fetch.

 

BTW - I believe your loop logic is incorrect. Fetch array will return 1 row at a time, what you're doing is calling the array keys -- which turns out to be different column for one row.

Link to comment
https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771544
Share on other sites

Actually you count the number of rows by:

$num_rows = mysql_num_rows($result);

 

Correct, but when you call:

$result = mysql_fetch_array($result);

 

It'll return 1 row result, not a multi-dimension array of the results.

Returns an array of strings that corresponds to the fetched row' date=' or FALSE if there are no more rows. [/quote']

 

@OP:

I'm guessing this is what you are aiming for, which doesn't make sense unless you allow duplicate usernames.

function someFunction($user) {
global $con;
$q = "SELECT `ID` FROM `userinfo` WHERE `username` = '$user'";
$result = mysql_query($q, $con) or die(mysql_error);

$r = array();
while ($row = mysql_fetch_array($result))
{
$r[] = $row['ID'];
}
return $r;
}

 

If you explain your goal a bit more, I can show a better example

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/146955-mysql_num_rows-error/#findComment-771589
Share on other sites

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.