Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To 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 12th, 2011, 02:06 AM
Authorized User
 
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default php login code problem

hi all,
i have created one simple login form to verify only username and password.i have created username as admin and password as admin123 in phpmyadmin database.
now if only both the username and password matches then it should display success message.
but for me after giving username name as admin and password as admin123 it is asking for "whether to save or download the file" instead of displaying the message as "login is successfull".why it is asking that one.whats woron in my code.....
below is my code....
login.html
Code:
<form name="form1" method="post" action="checklogin.php">
<strong>Member Login </strong>
</br>
Username: <input name="myusername" type="text" id="myusername" />
</br>
Password: <input name="mypassword" type="password" id="mypassword" />
</br>
<input type="submit" name="Submit" value="Login" />
</form>
it is checklogin.php
Code:
<?php
// Connect to server and select databse.
mysql_connect("localhost", "root", "")or die("cannot connect"); 
mysql_select_db("test")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM users 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:login_success.php");
}
else 
{
echo "Wrong Username or Password";
}
?>
it is login_success.php
Code:
<? 
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<body>
Login Successful
</body>
</html>
tell me what went wrong





Similar Threads
Thread Thread Starter Forum Replies Last Post
login php Case Problem saifi4u PHP How-To 3 March 7th, 2007 12:58 AM
PHP Login script problem columbo1977 Beginning PHP 1 May 21st, 2006 10:47 PM
No login with auth_user.php stefanocinfo BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 September 10th, 2005 03:34 AM
Php login session problem programmer Beginning PHP 1 August 3rd, 2004 03:57 AM
CH. 14 cart.php code problem shawnrberg BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 June 21st, 2004 05:44 PM





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