Jump to content

Login...username


e4games

Recommended Posts

So for the code login.php I used the on "justsomeguy" did but I have some questions on how to make the login code so it says username other then email..Main Code

<?phpsession_start();require_once 'db.php';$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';$error_string = '';if ($page_mode == 'login'){  $email = $_POST['email'];  $password = $_POST['password'];  if (trim($email) == '' || trim($password) == '')	$error_string .= 'Please enter your email address and password.<br>';  else  {	$result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'");	if (!($row = mysql_fetch_assoc($result)))	  $error_string .= 'The email address was not found.<br>';	elseif ($row['password'] != sha1($password))	  $error_string .= 'The password did not match.<br>';	else	{	  $_SESSION['user_id'] = $row['id'];	  $_SESSION['user_name'] = $row['name'];	  $_SESSION['user_email'] = $row['email'];	  header('Location: index.php');	  exit();	}  }}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>  <head>	<title>Register</title>	<style type="text/css">	.error_text {	  color: #FF0000;	  width: 400px;	  text-align: center;	}	.left_box {	  float: left;	  width: 150px;	  text-align: right;	  padding-right: 5px;	}	.right_box {	  clear: right;	}	</style>  </head>  <body>	<div class="error_text"><?php echo $error_string; ?></div>	<form action="login.php" method="post">	<input type="hidden" name="page_mode" value="login">	<div class="left_box">Email</div>	<div class="right_box"><input type="text" name="email" size="30" maxlength="255" value="<?php if (isset($email)) echo $email; ?>"></div>	<div class="left_box">Password</div>	<div class="right_box"><input type="password" name="password" size="30"></div>	<div class="left_box"> </div>	<div class="right_box"><input type="submit" value="Log In" size="30"></div>	</form>  </body></html>

I know this part of it

 <div class="left_box">Email</div>	<div class="right_box"><input type="text" name="email" size="30" maxlength="255" value="<?php if (isset($email)) echo $email; ?>"></div>

Should be changed to Username, at the top part, and the name="email" should be name="username" and "echo $email" should be echo $usernameBut I don't know about these parts

$_SESSION['user_email'] = $row['email'];

this one

$result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'");	if (!($row = mysql_fetch_assoc($result)))

and this one

$email = $_POST['email'];

Please help! I think I already changed what I needed to in the register.php

Link to comment
Share on other sites

Good so far, you know where to change, now here's what you need to change:

$_SESSION['user_email'] = $row['email'];

Can stay the same, since you may still need to call $_SESSION['user_email'] on other pages.

$result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'");

That can turn into this, since you are searching for their username, not email this time.

$result = db_query("SELECT id, name, password FROM users WHERE name='" . mysql_real_escape_string($username) . "'");

$email = $_POST['email'];

Last, change the above code with this:

$username = $_POST['username'];

I change $_POST['email'] to $_POST['username'] because the 'name' of the first input is now 'username', instead of 'email'

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...