Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Login page help!


[SOLVED] Login page help!

Reply
  #1 (permalink)  
Old 03-15-09, 05:30 AM
Laertes Laertes is offline
New Member
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Login page help!

Hi, I am new to PHP and MySQL but I decided that I would take on the challenge of creating a game and learn as I go. I have a nice layout and information for my pages, but when I try to login it displays the error "Please enter a username" and I think I have it set correctly to display that if the username field is left blank, but it displays even if I enter my username and password.

Here is the php code for index.php(equivalent to login.php).

Code:
<?php
session_start();
EOF;
$ip = ($_SERVER['HTTP_X_FORWARDED_FOR'])
    ?  $_SERVER['HTTP_X_FORWARDED_FOR']
    :  $_SERVER['REMOTE_ADDR'];
if(file_exists('ipbans/'.$ip))
{
die("<b><font color=red size=+1>Your IP has been banned, there is no way around this.</font></b></body></html>");
}
$dbhost = "mysql3.freehostia.com";
$dbname = "********";
$dbuser = "********";
$dbpass = "********";
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$dbhost = "mysql3.freehostia.com";
$dbname = "********";
$dbuser = "********";
$dbpass = "********";
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
?>
and this is the form for the index.php page
Code:
<form name="login" method="post" action="authenticate.php">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td width="50%"><b>Login</b></td>
      <td width="50%"><input name="login" type="text" class="textfield" id="login" /></td>
    </tr>
    <tr>
      <td width="50%"><b>Password</b></td>
      <td width="50%"><input name="password" type="password" class="textfield" id="password" /></td>
    </tr>
    <tr>
      <td width="50%">&nbsp;</td>
      <td width="50%"><input type="submit" name="Submit" value="Login" /></td>
    </tr>
  </table>
</form>
and this is the code for the authenticate.php

Code:
<?php

$dbhost = "mysql3.freehostia.com";
$dbname = "********";
$dbuser = "********";
$dbpass = "********";
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

if(empty($_POST['username']))
{
	die("Please enter a username.");
}
$query = "SELECT `username`,`password` FROM user WHERE `username`='".$username."'";
$username."'";
$result = mysql_query($query);
if(mysql_num_rows($result)!=1)
{
	die('We don\'t have a user called '.$username.'. If this is your first visit to our website, you may need to <a href="../register.php">create an account</a>. Otherwise, check your spelling.');
}
while($record = mysql_fetch_assoc($result))
{
	if(md5($password)!=$record['password'])
	{
		die("You provided an incorrect password. Please try again.");
	}
}

?>
Thanks in advanced for any help given,
Laertes.

Last edited by Laertes; 03-15-09 at 05:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-15-09, 05:51 AM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
You're grabbing the wrong post value. You've given your input a name of "login" not "username". Either change the php to "login", or the input to "username".

Also.. you've just posted your db host, user and pass publicly. Now anyone can access it.
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-15-09, 05:52 AM
Laertes Laertes is offline
New Member
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
oh crud didnt realize it, guess I gotta change the info...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] session expires reverting to login page melissa_octo7 PHP 3 06-05-08 10:15 AM
Login system pjking PHP 2 06-09-07 05:34 AM
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
need help creating an update & confirm page mikewooten PHP 1 11-08-04 05:28 PM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM


All times are GMT -5. The time now is 10:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.