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 March 21st, 2004, 08:43 PM
bokerfest bokerfest is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 3 bokerfest User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP/mySQL Login Page

This is my first time to the forum so hopefully my code is clearly visible.

I am new to PHP, but as far as I can tell my code should be working properly. The problem is that I keep getting a error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/oddprod/public_html/login.php on line 42.

As far as I can tell there is nothing wrong with that.


PHP Code:
//check that the user is calling the page from the login form and not accessing it directly 
 //and redirect back to the login form if necessary 
  
if (!isset($username) || !isset($password)) { 
   
header"Location: URL" ); 
  } 
 
//check that the form fields are not empty, and redirect back to the login page if they are 
    
elseif (empty($username) || empty($password)) { 
    
header"Location: URL" ); 
    } 
  else{ 
  
//convert the field values to simple variables 
  //add slashes to the username and md5() the password 
  
$user addslashes($_POST['username']); 
  
$pass md5($_POST['password']); 

// Connect to DB
$db mysql_connect ("localhost""username""password")
 or die (
'I cannot connect to the database because: ' mysql_error());

$db_selected mysql_select_db('oddprod_managment'$db);
if (!
$db_selected) {
   die (
'Can\'t use oddprod_managment : ' mysql_error());
}
// making sure the that the information from the form exists in the DB
$result=mysql_query("select * from users where username='$usersLOGIN' AND password='$usersPASS'"$db); 
// check that at least one row was returned 
$rownum mysql_num_rows($result); 
 if(
$rownum 0){ 
 
 while(
$row mysql_fetch_array($result)){ 
 
//start the session and register a variable 
 
session_start(); 
 
session_register('user'); 

//successful login code will go here... 
 
echo 'Success!'

//we will redirect the user to another page where we will make sure they're logged in 
 
header"Location: index.php" ); 
 } 
 } 
 else { 

//if nothing is returned by the query, unsuccessful login code goes here... 
echo 'Incorrect login name or password. Please try again.'
  } 
  } 
  

mysql_close($db); 

Reply With Quote
  #2  
Old March 22nd, 2004, 03:00 AM
richardtham richardtham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 richardtham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I faced a similar problem last week and the problem has been resolved. Pls check here for more info:

http://forums.devarticles.com/t7306/s.html

Reply With Quote
  #3  
Old March 24th, 2004, 09:41 AM
tobycloud tobycloud is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Near Albany NY
Posts: 27 tobycloud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to tobycloud Send a message via AIM to tobycloud
Your query ($result) is not returning a value. Therefore, you can'tfind the number of rows to a broken query. Fix the query, then it'll work.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > PHP/mySQL Login Page


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 1 hosted by Hostway