Jump to content

Problem with this


Chidori Soul

Recommended Posts

Hey, I am making a Login code, and everything is complete, but it is not working properly. The error is this: Even though I enter everything correctly, it always says that the password is incorrect? My code is this:

 

<?php

session_start();

require_once 'db.php';

$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';

$error_string = '';

if ($page_mode == 'login')
{
  $name = $_POST['name'];
  $password = $_POST['password'];

  if (trim($name) == '' || trim($password) == '')
$error_string .= 'Please enter your username and password.<br>';
  else
  {
	$result = db_query("SELECT id, name, password FROM users WHERE name='" . mysql_real_escape_string($name) . "'");
if (!($row = mysql_fetch_assoc($result)))
  $error_string .= 'The username was not found.<br>';
else if ($row['password'] != sha1($password))
  $error_string .= 'The password does not match the username provided.<br>';
else
{
  $_SESSION['user_id'] = $row['id'];
  $_SESSION['user_name'] = $row['name'];
  header('Location: index.php');
  exit();
}
  }
}
?>
<html><center>
<head>
<title>Pokemon Planet - Version 0.1</title>
<link rel='stylesheet' type='text/css' href='stylesheet.css'>
<body><div class="error_text"><?php echo $error_string; ?></div>
<div id="container">
<div id="banner"></div>
<div id="frame">
	<div id="leftmenu"><div style="padding: 3px;">
		<center><b>General Options</b><br/><a href='index.php'>Index</a><br/><a href='register.php'>Register</a><br/><a href='login.php'>Login</a></center>
	</div></div>

	<div id="content"><div style="padding: 3px;">
		<center><u>Login!</u><br/>Here you can login to access the RPG, but you have to have already <a href='register.php'>registered</a>.<br/><br/><form action="login.php" method="post"><input type="hidden" name="page_mode" value="login"><b>Username:</b><br/><input type="text" name="name" size="20" maxlength="255" value="<?php if (isset($name)) echo $name; ?>"><br/><br/><b>Password:</b><br/><input type="password" name="password" size="20"><br/><input type="submit" value="Log In" size="30"></center>
	</div></div>
	<div id="rightmenu"><div style="padding: 3px;">
		<center><b>General Options</b><br/><a href='index.php'>Index</a><br/><a href='register.php'>Register</a><br/><a href='login.php'>Login</a></center>
	</div></div>
</div>
<div id="footer"><center><font color='#000000'>Pokemon Planet is © 2009 by Shadow. This site is created and coded by Shadow. Pokemon Planet is in no way affiliated with Nintendo, Pokémon Company, Game Freak, Creatures, or any related organizations. Most Pokémon images (sprites, icons, map tiles, etc.) are © Nintendo and their publishers. Images are slightly modified in order to meet certain needs upon this website.</font></center></div>
</div></body></center>
</html>

Link to comment
https://forums.phpfreaks.com/topic/171727-problem-with-this/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.