General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

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:
  #1  
Old September 18th, 2003, 09:31 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
getting userdata at page start.?

Hi, im trying to get some user details from the database if they have a cookie set. I have the foollowing piece of code, but i dont understand what certain lines do or if it is a good way to get user info?
Heres what i have
PHP Code:
function check_user_session($cuser$cpass){
global 
$db;

    
$sql "SELECT * FROM user_users WHERE username='$cuser' AND password='$cpass' AND activated='1'";
    if ( !(
$result $db->sql_query($sql)) ) <-- WHAT DOES THIS DO?
    {
        
message_die('Error doing DB query userdata row fetch'$sql);
    }

    
$userdata $db->sql_fetchrow($result); <-- WHAT DOES THIS DO?
return (
$userdata);


How would i use such a function?
__________________
regards,


Fulton

Reply With Quote
  #2  
Old September 19th, 2003, 07:06 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
The first line you've questioned runs the query stored in $sql and prints an error message if the query fails to execute. The second line executes only if the query is successfully executed (the die() function stops program execution), and it returns an array of database results your query retrieved.

You would use such a function by retrieving a username and password through a form and doing something like the following:

PHP Code:
 $userdata=check_user_session($username,$password);  
if(
sizeof($userdata)==1){
    print 
"Valid user!";
}
else{
    print 
"Invalid user or multiple rows for this account.";



It's pretty basic stuff; if it seems a little gibberishy to you, I recommend that you pick up a book on PHP and start with the basics. Doing so will make your programming efforts much easier.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > getting userdata at page start.?


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