Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 17th, 2011, 07:12 AM
Authorized User
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......

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$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'";

// Mysql_num_row is counting table row
// If result matched $myusername and $mypassword, table row must be 1 row
// Register $myusername, $mypassword and redirect to file "login_success.php"
echo "Wrong Username or Password";
Old November 12th, 2011, 02:56 PM
Authorized User
Join Date: Feb 2007
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post

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.
Amitav Roy

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

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