Jump to content

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


robcrozier

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]

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.