TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05-07-2008, 07:56 PM   #1 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default Checking a users login details against a database

I'm making a very simple login script, here's what I have so far:

Code:
<?
//Connect to the database
include("../config/connect.php");

//Get the data from the form
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];

//Check the fields arent empty
if(empty($UserName)) {
	echo "Please Enter A Username";
}elseif(empty($Password)){
	echo "Please Enter A Password";
//Theyre all fine, lets continue
}else {	

//Get rid of any nasty inputs
$UserName = mysql_real_escape_string($UserName);
$Password = mysql_real_escape_string($Password);

$query = "SELECT * from tbl_users WHERE UserName = '$UserName' AND Password = '$Password'";

$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) {
	echo $row['UserName'];
}
}
?>
It all works fine but I was wondering. What is the best way to see if the users details matched what was in the database or not?

I've tried putting the following in the while loop:
Code:
if(empty($row['UserName'])) {
echo "Not Logged In";
}else{
echo "Logged In";
}
But it doesn't seem to work
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:09 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design