Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 8th, 2005, 6:02 AM   #1
stakeknife
Newbie
 
Join Date: Mar 2005
Posts: 16
Rep Power: 0 stakeknife is on a distinguished road
Urgent help needed with login form

I wrote a login form to access the admin area of my program. It takes the username and password selects them from the db based on the username and compares them to the values taken in. All seems well codewise but the program just reloads the form no error, no continuation to the next page... any ideas?

Thanks in advance, i have written this script which is used for logging users into an admin area. From what i can see its perfectly okay but... when i hit submit it just reloads the form

[php]<?php
if(!$submit)
{
?>
<html>
<head>
<title>User Login</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div>
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br />
</div>
</form>
</body>
</html>

<?php
}
else
{
include ("db.php");
$sql = mysql_query("SELECT user_name, user_password FROM core_users WHERE user_name = '$username'");
$fetch_em = mysql_fetch_array($sql);

if($username == $fetch_em["user_name"] && $password == $fetch_em["user_password"])
{
session_start();
session_register("sessionvar");
$id = session_id(); //gets the session id if cookies are disabled
$url = "Location: admin_launch.php?sid=" . $id;
header($url);
}
else
{
?>
<html>
<head>
<title>User Login</title>
</head>
<body>
<span style="color:#ff0000;">Password/Username Is Invalid</span><br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div>
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br />
</div>
</form>
</body>
</html>

<?php
}
}
?>[/php]

Last edited by big_k105; Apr 8th, 2005 at 10:03 AM. Reason: added php tags
stakeknife is offline   Reply With Quote
Old Apr 8th, 2005, 7:50 PM   #2
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
running your code in my mind, I noticed you dont adress the form variables correctly change the submit check to !isset($_POST['submit']) and the variable $username with {$_POST['username']} i think this should solve your problem

tell me if not

-codetaino

EDIT: Atention: Notice that your form send the variables as post and in order to access those variables you need to write $_POST['nameoffield']. English is not my first language and sometimes is hard for me to explain myself so... ask me if you need further help or explanation
__________________
"God bless u all" :)

Last edited by codetaino; Apr 8th, 2005 at 7:52 PM.
codetaino is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC