Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

mysql_numrows() error in php

Original Message
Name: jake1025
Date: August 9, 2004 at 20:26:02 Pacific
Subject: mysql_numrows() error in php
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


Report Offensive Message For Removal


Response Number 1
Name: Laler
Date: August 10, 2004 at 00:38:18 Pacific
Subject: mysql_numrows() error in php
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 2
Name: jake1025
Date: August 12, 2004 at 20:59:48 Pacific
Subject: mysql_numrows() error in php
Reply: (edit)
thanks for your help but im still having problems. it turns out that whenever a php-primitive function is called, there's an error

Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: mysql_numrows() error in php

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




Video/Graphics problem

Ping on DOS 6.22

netgear, onelevel

Ping on DOS 6.22

Sony handycam dcr-sr42


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC