Computing.Net > Forums > Web Development > mysql_numrows() error in php

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

mysql_numrows() error in php

Reply to Message Icon

Name: jake1025
Date: August 9, 2004 at 20:26:02 Pacific
OS: XPhome
CPU/Ram: 800/128
Comment:

Im trying to make a logon script in PHP. When I run the webpage i get an error that says:

[error]
mysql_numrows(): supplied argument is not a valid MySQL result resource in [dir] on line 79
[/error]

Here's my code:

[code]
<?
$sqlusername="root";
$sqlpassword="fakepassword";
$database="webspace";

mysql_connect('localhost',$sqlusername,$sqlpassword);
@mysql_select_db($database) or die( "Unable to connect to database!");

$query="SELECT * FROM main WHERE field='username'";
$result=mysql_query($query);

//#####PROBLEM######//
$num=mysql_numrows($result);
//#####PROBLEM######//

$i=0;
$verify=0;

while ($i < $num) {
$compare=mysql_result($result,$i,"username");
if ($username == $compare){
$verify=1;
$row=$i;
}
else
{
$i++;
}
}

if ($verify == 1){
$query="SELECT * FROM main WHERE field='password'";
$result=mysql_query($query);
$compare=mysql_result($result,$row,"password");
if ($compare == $password){
print "Done!";
}
else
{
print "HAHAHAHAHAHA! You forgot your password!";
}
}

if($verify != 0){
print $username;
print " is a non-existing username! That or Jake can't program PHP for sh*t!";
}

mysql_close();
?>

[/code]

How do i fix this? Or is there an another way of counting the number of rows in a sequence?
Thanks in advance for any help!
Jake



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: August 10, 2004 at 00:38:18 Pacific
Reply:

I don't see anything wrong with this query... but if it's me I'd do it by the book, like this:

$query = "SELECT * FROM `main` WHERE `field` = 'username'";

$result = mysql_query($query) or die (mysql_error());

$num = mysql_num_rows($result);

sometimes that ' and ` can really make a difference :D

mysql_numrows() is deprecated

mysql_error() will show you more details if the query was wrong, something like: 'you have an error in your syntax near: FROM `main`... so you can look at that section more closely...

hope that helps

^o^
are you in Asia? do you watch Animax Asia? Please Vote


0

Response Number 2
Name: jake1025
Date: August 12, 2004 at 20:59:48 Pacific
Reply:

thanks for your help but im still having problems. it turns out that whenever a php-primitive function is called, there's an error


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: mysql_numrows() error in php

Error in PHP Script www.computing.net/answers/webdevel/error-in-php-script/2599.html

error in php www.computing.net/answers/webdevel/error-in-php/3595.html

enable error reporting in PHP www.computing.net/answers/webdevel/enable-error-reporting-in-php/341.html