Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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