Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 17th, 2011, 07:12 AM
Authorized User
Points: 223, Level: 4
Points: 223, Level: 4 Points: 223, Level: 4 Points: 223, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default username and password verification

hi all,
my database name is "test".in the "test" database
i have created a table name called "log" which has two fields
namely username and password.
i have given username as "admin" and password as "admin123".
now i have written one code using php so that when i click the submit button both the username as "admin" and password as "admin123" gets matched then it should direct to the next page...
tell me how to check whether username and passwords are matching and if it matches it must point to the action part what we give in <form method="POST" action="www.php">
kindly tell me what i must add to the below program.....
below is the code in php......
Code:
<?php
$host="localhost";  
$username="root";  
$password="";  
$db_name="test"; 
$tbl_name="log"; 

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:www.php");
}
else 
{
echo "Wrong Username or Password";
}
?>
Reply With Quote
  #2 (permalink)  
Old November 12th, 2011, 02:56 PM
Authorized User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: Vashi, Maharashtra, India.
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
Default

the code that you have provided here should do the trick.
it is doing everything which is required for the checking and redirecting if the username and password are right.
__________________
Regards
Amitav Roy
Web:
http://www.amitavroy.com/justread
http://www.pixelgroups.com
Reply With Quote
Reply


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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
username verification ravi951 Javascript 21 July 21st, 2011 03:24 AM
Regarding Username and password kuku_ashu Javascript How-To 0 January 4th, 2008 11:28 AM
username and password abhi_loveu2002 ASP.NET 2.0 Basics 1 December 14th, 2006 05:25 AM
Password Strength Verification vinodhanandhan .NET Framework 1.x 0 December 10th, 2006 04:45 AM
Username and password Hennie Access 1 July 28th, 2006 12:43 AM



All times are GMT -4. The time now is 11:25 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.