Jump to content

Help with stupid error (mysql_num_rows)!!!!!!!


Recommended Posts

Ok can anyone help me here. I've been working on this for ages and i just don't understand why this error keeps appearing with reference to the code below:

[code]

$query = "select username from customer
where username = '$template_client_username'";
$result = mysql_query($query);

if (mysql_num_rows($result) == 0)
{
//username is free, break the loop as username is now set
break;
}
else
{
//loop again
}

[/code]

This is the error that i keep getting, however bare in mind that it only appears when no valid match is found in the database resulting from the query. If there is a match found the error doesn't appear.

[code]

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\????????\????????\????????.php on line 164

[/code]

Thanks for taking a look!
Link to comment
https://forums.phpfreaks.com/topic/27999-help-with-stupid-error-mysql_num_rows/
Share on other sites

Are you properly connecting to the database? Are the table and column names correct?

Plus you have no error handling on the query call itself.

try this:

[code]<?php
$query = "select username from customer
where username = '$template_client_username'";
$result = mysql_query($query) OR die ("The query <br>".$query."<br>casued the following error<br>".mysql_error());

if (mysql_num_rows($result) == 0)
{
//username is free, break the loop as username is now set
break;
}
else
{
//loop again
}

?>[/code]
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.