MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 24th, 2003, 07:54 AM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Supplied argument is not valid MySQL result resource?

Hi there everyone,

Long time ive been away! now im back on the php trail doing a little revision.

Anyway, I have created the following username / password login script:

PHP Code:
<?
extract
($_Post);
$link mysql_connect("localhost""uname""pass");
mysql_select_db("auth"$link);

$name mysql_query("SELECT name FROM logstudent WHERE name = '$logon' AND pass = '$password'"$link);
$num_rows mysql_num_rows($name);

if (
$num_rows <= 0)
        {
             echo 
"<p align=center>You either entered your user name or password wrong. </p>";
exit;
        }
echo 
"<p align=left>You are now logged in</p>";
include (
"showdetails.php");
?>


I keep getting the following warning: -

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\www\checkstudent.php on line 8
(line 8 is : $num_rows = mysql_num_rows($name);

I know that I am supplying the correct username and password, so it has to be something with the actual database/table?

Can anyone explain what this error means so I can track down the problem further.

Also, the database is called "auth", and there are 2 columns called: - "logon" for usernames ans "password" for passwords"

As always, thanX in advance.
__________________
SAFC

Last edited by Gee : July 24th, 2003 at 08:11 AM.

Reply With Quote
  #2  
Old July 24th, 2003, 08:57 AM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Don't extract your superglobals, it makes for unreadable and unmanageable code in the long term.

If you're having problems with a query, tack on what i've tacked onto the mysql_query() below to see the error AND your sql statement so you can compare the error message to what you're trying to send the db.
PHP Code:
<?
$link 
mysql_connect("localhost""uname""pass");
mysql_select_db("auth"$link);

$sql "SELECT name FROM logstudent WHERE name = '".$_POST['logon']."' AND pass = '".$_POST['password']."';";

$name mysql_query($sql$link) or die(mysql_error().'<br> SQL:'.$sql);
$num_rows mysql_num_rows($name);

if (
$num_rows <= 0)
        {
             echo 
"<p align=center>You either entered your user name or password wrong. </p>";
exit;
        }
echo 
"<p align=left>You are now logged in</p>";
include (
"showdetails.php");
?>

Reply With Quote
  #3  
Old July 24th, 2003, 10:01 AM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Thanks crazytrain, that got to the bottom of my problem right away! I will use that method from now on.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Supplied argument is not valid MySQL result resource?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway