Programming Theory
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesProgramming Theory

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old January 23rd, 2004, 02:56 AM
bluephoenix's Avatar
bluephoenix bluephoenix is offline
Levelheaded Curmudgeon
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Syracuse, NY
Posts: 507 bluephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 13 m 2 sec
Reputation Power: 2
Send a message via AIM to bluephoenix
Handling Single-Column Single-Record Mysql Result

I'm helping a friend stumble through writing some very basic authentication scripts using php and mysql.

Our relevent PHP code follows:
php Code:
Original - php Code
  1. <?php
  2.   $name = $_POST['name'];
  3.   $password = $_POST['pass'];
  4.  
  5.   $server = mysql_connect("localhost", "PHPUSER", "PHP123");
  6.   mysql_select_db("DND");
  7.   $result = mysql_query("SELECT USER_PASSWD FROM DNDAUTH WHERE USER_ID='$name'")
  8.             or die("Invalid Query!" . msql_error());
  9.  
  10.   list($incomming_password) = mysql_fetch_row($result);
  11.   mysql_close($server);
  12.  
  13.   if ($password == $incomming_password)
  14.     echo "$name authenticated.";
  15.   else
  16.     header("Location: login.html");
  17. ?>


I really couldn't see the use of forming the query SELECT * FROM DNDAUTH because we're only interested in the one value, USER_PASSWD. But it seems a bit of a waste to extract the value out through an array and then through list().

Is there a better way to do this, or is this pretty much standard and it just seems weird to me because we're returning a single column single record?

Thanks.

Tim

Reply With Quote
  #2  
Old January 23rd, 2004, 03:09 AM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: Handling Single-Column Single-Record Mysql Result

I'd code authentication scripts in this way. Just check it out, you'll see what I do.
php Code:
Original - php Code
  1.  
  2. <?php
  3.   $name = $_POST['name'];
  4.   $password = $_POST['pass'];
  5.  
  6.   $server = mysql_connect("localhost", "PHPUSER", "PHP123") or die("Couldn't connect");
  7.   mysql_select_db("DND",$server) or die("Couldn't select DB");
  8.   $result = mysql_query("SELECT USER_ID,PASSWD FROM DNDAUTH WHERE USER_ID='$name' AND PASSWD='$password'")
  9.             or die("Invalid Query!" . mysql_error());
  10.  
  11.   mysql_close($server);
  12.  
  13.   if (mysql_num_rows($result)>0)
  14.     echo "$name authenticated.";
  15.   else
  16.     header("Location: login.html");
  17. ?>

Reply With Quote
  #3  
Old January 23rd, 2004, 03:12 AM
bluephoenix's Avatar
bluephoenix bluephoenix is offline
Levelheaded Curmudgeon
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Syracuse, NY
Posts: 507 bluephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 13 m 2 sec
Reputation Power: 2
Send a message via AIM to bluephoenix
RE: Handling Single-Column Single-Record Mysql Result

pretty sly

Thanks!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesProgramming Theory > Handling Single-Column Single-Record Mysql Result


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