Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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
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
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
![]() |
![]() |
![]() |

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