/    Sign up×
Community /Pin to ProfileBookmark

login page not logging in?

I’ve made a login page and when the user logs in it should redirect. the page is [URL=”http://www.roondogid.co.uk/fm/login.php”]here[/URL]I’ve made a user for anyone to test it. Gamertag = user password = test

here is the code

[code=php]
<?php

$page_title = ‘Login’;
include (‘./header.html’);
if (isset($POST[‘submitted’])) {
require_once (‘./mysql_connect.php’);
if (!empty($_POST[‘gamertag’])) {
$g = escape_data($_POST[‘gamertag’]);
}else{
echo “<p class=’error’>You Forgot to enter your Gamertag!</p>”;
$g = FALSE;
}
if (!empty($_POST[‘pass’])) {
$p = escape_data($_POST[‘pass’]);
}else{
echo “<p class=’error’>You Forgot to enter your Password!</p>”;
$p = FALSE;
}
if ($g && $p) {
$query = “SELECT user_id, first_name FROM users WHERE (gamertag=’$g’ AND pass=SHA(‘$p’)) AND active IS NULL”;
$result = mysql_query ($query) or trigger_error(“Query: $queryn<br />MySQL Error: ” . mysql_error());
if (@mysql_num_rows($result) == 1) {
$row = mysql_fetch_array ($result, MYSQL_NUM);
mysql_free_result($result);
mysql_close();
$_SESSION[‘first_name’] = $row[1];
$_SESSION[‘user_id’] = $row[0];
$url = ‘http://’ . $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]);
if ((substr($url, -1) == ‘/’) OR (substr($url, -1) == ‘\’) ) {
$url = sustr ($url, 0 ,-1);
}
$url .= ‘/index.php’;
ob_end_clean();
header(“Location: $url”);
exit();
}else{
echo “<p class=’error’>Either the Gamertag and password entered do not match those on file or you have not activated your account.</p>”;
}
}else{
echo “<p class=’error’>Please try again</p>”;
}
mysql_close();
}
?>
<h1>Login</h1>
<form action=”login.php” method=”post”>
<fieldset>
<p>Gamertag: <input type=”text” name=”gamertag” size=”20″ maxlength=”20″ value=”<?php if (isset($_POST[‘gamertag’])) echo $_POST[‘gamertag’]; ?>” /></p>
<p>Password: <input type=”password” name=”pass” size=”20″ maxlength=”20″ /></p>
<div align=”center”><input type=”submit” name=”submit” value=”Login” /></div>
<input type=”hidden” name=”submitted” value=”TRUE” />
</fieldset>
</form>
<?php
include (‘./footer.html’);
?>
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@tcaJun 16.2007 — if (isset($POST['[B]submitted[/B]'])) {

<input type="submit" name="[B]submit[/B]" value="Login" />

Change $POST['submitted'] to $_POST['submit']

or

change name="submit" to name="submitted"

Correct syntax: $_POST['variable']

I really don't see why you need this line:

<input type="hidden" name="submitted" value="TRUE" />

TC
×

Success!

Help @roondog spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...