By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

i'm confused and don't know what to do, i need your help

P: 20
i have developed a log in system which is a starting point for my online learning system i'm developing.
i'm failing to log in possibly the system is not able to register a user as a valid user.The system is not reflecting error warnings.
Here is a code section where i'm suspecting a fault.

[PHP]
function login($username, $passwd)
// check username and password with db
// if yes, return true
// else return false
{
// connect to db
$conn = db_connect();
if (!$conn)
return 0;

// check if username is unique
$result = mysql_query("select * from users
where username = '$username'
and passwd = '$passwd'");
if (!$result)
return 0;

if (mysql_num_rows($result)>0)
return 1;
else
return 0;
}

function check_valid_user()
// see if somebody is logged in and notify them if not
{
global $valid_user;
if (session_is_registered("valid_user"))
{
echo "Logged in as $valid_user.";
echo "<br>";
}
else
{
// they are not logged in
do_html_heading("Problem:");
echo "You are not logged in.Please try again.<br>";
do_html_url("login.php", "Login");
//do_html_footer();
exit;
}
}


<?
session_start();
// include function files for this application
require_once("system_fns.php");
if (isset($username) && isset($passwd))
// they have just tried logging in
{
if (login($username, $passwd))
{
// if they are in the database register the user id
$valid_user = $username;
session_register("valid_user");
}
}
check_valid_user();
// give menu of options
display_user_menu();
[/PHP]

if i enter the log in button it doesnot show any error messages but simply says Please try again logging in.i have created a user in a database and now i don't know what to do, please help.
Feb 14 '07 #1
Share this Question
Share on Google+
10 Replies


ronverdonk
Expert 2.5K+
P: 4,258
I cannot see it, but where did you fill these variables?
Expand|Select|Wrap|Line Numbers
  1. if (isset($username) && isset($passwd))
Ronald :cool:
Feb 14 '07 #2

P: 20
I cannot see it, but where did you fill these variables?
Expand|Select|Wrap|Line Numbers
  1. if (isset($username) && isset($passwd))
Ronald :cool:
These are values the user inputs when he logs in
[HTML]
<a href='register_form.php'>Not a member?</a>
<form method='post' action='member.php'>
<table bgcolor=''>
<tr>
<td colspan=2>Members log in here:</td>
<tr>
<td>Username:</td>
<td><input type='text' name='username'></td></tr>
<tr>
<td>Password:</td>
<td><input type='password' name='passwd'></td></tr>
<tr>
<td colspan=2 align='center'>
<input type='submit' value='Log in'></td></tr>
<tr>
<td colspan=2><a href='forgot_form.php'>Forgot your password?</a><br>
<a href='change_passwd.php'>Change your password?</a></td>
</tr>[/HTML]
Feb 15 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
You did not answer the question: where did you fill those 2 variables in the following statement???

[php]if (isset($username) && isset($passwd))[/php]

Becasue as I can see it , they are not defined or filled anywhere in the code you showed.

Ronald :cool:
Feb 15 '07 #4

P: 20
I cannot see it, but where did you fill these variables?
Expand|Select|Wrap|Line Numbers
  1. if (isset($username) && isset($passwd))
Ronald :cool:
It was a stupid error I was doing coz I was validating the entered username and password using the wrong table name.

However its not done yet though I can register a new user and log in, I'm now working on resetting a forgotten password as well as changing the password.

Guys you are wonderful I thank you for your support keep it up.
Feb 15 '07 #5

P: 20
You did not answer the question: where did you fill those 2 variables in the following statement???

[php]if (isset($username) && isset($passwd))[/php]

Becasue as I can see it , they are not defined or filled anywhere in the code you showed.

Ronald :cool:
Its true that I didn't understand your question when I replied but however I have managed to figure out where I was missing it.
My system is now logging in and registering a new user but its failing to reset a forgotten password and changing password.

Thanks!!!
Feb 15 '07 #6

ronverdonk
Expert 2.5K+
P: 4,258
You are welcome.

Ronald :cool:
Feb 15 '07 #7

P: 20
You are welcome.

Ronald :cool:
My bro help to get out this problem.My system cannot change or reset password.
Here are the codes.
[PHP]<?
require_once("system_fns.php");
session_start();
do_html_header("Changing password");
check_valid_user();
$new_passwd=($HTTP_POST_VARS['new_passwd']);
$new_passwd2=($HTTP_POST_VARS['new_passwd2']);
if (!filled_out($HTTP_POST_VARS))
{
echo "You have not filled out the form completely.
Please try again.";
display_user_menu();
exit;
}
else
{
if ($new_passwd!=$new_passwd2)
echo "Passwords entered were not the same. Not changed.";
else if (strlen($new_passwd)>16 || strlen($new_passwd)<6)
echo "New password must be between 6 and 16 characters. Try again.";
else
{
// attempt update
if (change_password($valid_user, $old_passwd, $new_passwd))
echo "Password changed.";
else
echo "Password could not be changed.";
}


}
display_user_menu();
?>
[/PHP]
these are the errors i'm getting
Notice: Undefined index: new_passwd in C:\project\test\change_passwd.php on line 6

Notice: Undefined index: new_passwd2 in C:\project\test\change_passwd.php on line 7
Feb 16 '07 #8

ronverdonk
Expert 2.5K+
P: 4,258
First: do not use the deprecated POST array, use $_POST.
Second: check the existence of the POSTed values before assignment.
Third: msanitize input ALWAYS!

So that piece of your code is to look like this:

[php]
if (!isset($POST['new_passwd']) OR !isset($_POST['new_passwd2'])) {
echo "You have not filled out the form completely.
Please try again.";
display_user_menu();
exit;
}
else {
$new_passwd =strip_tags(trim($_POST['new_passwd']));
$new_passwd2=strip_tags(trim($_POST['new_passwd2']));
if ($new_passwd!=$new_passwd2)
echo "Passwords entered were not the same. Not changed.";
// ... etc ....
[/php]

Ronald :cool:
Feb 16 '07 #9

P: 20
First: do not use the deprecated POST array, use $_POST.
Second: check the existence of the POSTed values before assignment.
Third: msanitize input ALWAYS!

So that piece of your code is to look like this:

[php]
if (!isset($POST['new_passwd']) OR !isset($_POST['new_passwd2'])) {
echo "You have not filled out the form completely.
Please try again.";
display_user_menu();
exit;
}
else {
$new_passwd =strip_tags(trim($_POST['new_passwd']));
$new_passwd2=strip_tags(trim($_POST['new_passwd2']));
if ($new_passwd!=$new_passwd2)
echo "Passwords entered were not the same. Not changed.";
// ... etc ....
[/php]

Ronald :cool:
Thanx its now working but one more problem its not resetting the password where it must send the new generated password to user via email.
this is the error i'm getting.

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for r042394a@cs.uz.ac.zw in C:\project\test\user_auth_fns.php on line 157
Your password could not be mailed to you. Try pressing refresh.Login
Feb 23 '07 #10

ronverdonk
Expert 2.5K+
P: 4,258
I don't think that you have specified a valid email address, as your error statement shows:

Expand|Select|Wrap|Line Numbers
  1. r042394a@cs.uz.ac.zw 
Ronald :cool:
Feb 23 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.