Left Quote    Wise men speak because they have something to say; Fools because they have to say something.
- Plato (427-347 B.C.)    
Right Quote
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply

        Viewing Topic: Member System Errors
  This user is offline  duece
  Subject: "Member System Errors" Posted: @ 4:17 am on Jun 17 2007   
Member #: 341
Rank: user - (14)
Since: 06/12/07
Posts: 14

Okay, so I ran through the tut. I went through and made some adjustments and wound up having a few problems. So I went back to the base code that was provided. Got rid of all of the errors but 1.
I am using the latest version of WAMP as a development server to learn PHP.

My error
Login Failure: An error occured, please verify your username and password are correct.

I have verified that this is NOT the case. Is there anything in particular that I need to make .md5 encryption to work ?
MyRegister.php< BR>Code:
require_once('. ./www/db_connec t.php');


if($_SESSION[' logged_in'] == 1)
header('Locatio n: http://localhos t/www/ p');
} else {

if(isset($HTTP _POST_VARS['sub mit']))


if(!$_POST['use rname']) die('Alert: username field was blank.');

//array of invalid characters
$junk = array('.' , ',' , '//' , '\\' , '`' , ';' , '[' , ']' , '-',
'*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')',
'|', '{', '}', '<', '>', '?', ':', '"', '=');

//starting lenght of username
$len = strlen($_POST[' username']);

//replace invalid characters
$_POST['usernam e'] = str_replace($ju nk, '', $_POST['usernam e']);
$test = $_POST['usernam e'];

//if lenghts are different ($len smaller), invalid characters found, so prompt error.
if(strlen($test ) != $len) {
die('Username Error: Username contained invalid characters. You can only use A-Z, 0-9 and the

underscore (_).');

//Check if username already exists...

$q2 = mysql_query(&qu ot;SELECT * FROM `familymembers` WHERE `username` = '".$_POST[ 'username'].&qu ot;'");
$q3 = mysql_fetch_obj ect($q2);

if($q3->user name == $_POST['usernam e']) {
die('<BR> ;<BR>Sorr y, but the username "'.$q3-> ;username.'&quo t; is taken, please choose another.');


if(!$_POST['pas sword']) {
die('Error: Password field was blank');
if(!$_POST['ver ify_password']) {
die('Error: Verify Password field was blank.');
if($_POST['pass word'] != $_POST['verify_ password']) {
die('Error: The passwords do not match.');
if(strlen($_POS T['password']) < 6 ) {
die('Error: Your password is too short. Must be 6 or more characters in length.');


$insert ="INSERT INTO `familymembers` (username, password, email) VALUES ('".$_POST ['username'].&q uot;',

'".md5($_P OST['password'] )."', '".$_POST[ 'email']." ')";

$insert2 = mysql_query($in sert);
if(!$insert2) die(mysql_error ());

echo('Registrat ion Successful, Welcome new member! You can now login to your new account.');

} else {
<table> <form name="sign up" action="&l t;?php $_SERVER['PHP_S ELF']; ?>" method="PO ST">
<td>Usern ame: <BR> (only A-Z, 0-9 and _ Allowed)<BR& gt;</td>< br /> <td><i nput type="text " id ="username " name="user name" value="&qu ot; maxlength=" ;30"> <BR></ td>
<td>Passw ord:</td>
<td><i nput type="pass word" id="passwo rd" name="pass word" value="&qu ot; maxlength=" ;30">&l t;BR> (minimum 6

characters)< /td>
<td>Verif y Pass:</td> ;
<td><i nput type="pass word" id="verify _password" name="veri fy_password&quo t; value="&qu ot; maxlength=" ;30">&l t;BR>

<td>Email :</td>
<td><i nput type="text " id="email& quot; name="emai l" value="&qu ot; size="30&q uot;><br& gt;</td>< br /> </tr>
<td>Click to Complete Signup:</td& gt;
<td><i nput type="subm it" id="submit " name="subm it" value="sub mit">&l t;/td>
</form>< br /> </table>
} //end not logged in
} //end submit not pressed

require_once('. ./www/db_connec t.php');

if(isset($_SESS ION['username'] ) && isset($_SESSION ['password'])) {
header("Lo cation: http://localhos t/MyPage.php&qu ot;);
} //end if logged in

if(isset($_POST ['submit'])) {

if(!$_POST['use rname']) die("Error : You must enter your username before logging in.");
if(!$_POST['pas sword']) die("Error : You must enter your password before logging in.");

//set cookie if checked
if(!empty($_POS T['stay_in'])) {
$joined =''.$_POST['use rname'].'[]'.md 5($_POST['passw ord']).'';
setcookie('logi n_cookie', $joined, 2147483647, '/', '.www.myfamily. com');
} //end if

//verify user...
$get_user = mysql_query(&qu ot;SELECT * FROM `familymembers` WHERE username = '".$_POST[ 'username'].&qu ot;' AND

password = '".md5($_P OST['password'] )."'" );
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Login Failure: An error occured, please verify your username and password are correct.") ;

//set session variables
$_SESSION['logg ed_in'] = 1;
$_SESSION['user name'] = $_POST['usernam e'];
$_SESSION['pass word'] = $_POST['passwor d'];
session_write_c lose();

header("Lo cation: http://localhos t/MyPage.php&qu ot;);

} else {
//show login form
<form name="logi n" method="po st" action="&l t;?php $_SERVER['PHP_S ELF']; ?>">
<table> <tr>
<td>Usern ame:<input type="text " id="userna me" name="user name">& lt;/td>
<td>Passw ord:<input type="pass word" id="passwo rd" name="pass word">& lt;/td>
<td>Submi t: <input type="subm it" value="Sub mit" name="subm it" id="submit "></ td>
<td>Remem ber? <input type="chec kbox" name="stay _in[]" checked="y es">< ;/td>
</table>< br /> </form> <?php
}//end else

I am a little confused about the header code that is given in the tutorial. This code is supposed to go at the top of each page... or at the top of the pages that I only want people to be able to navigate to IF they are logged in...?

    Viewed: 8,894 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Member System Errors" Posted: @ 3:48 am on Jun 19 2007    

Member #: 353
Rank: user - (27)
Since: 06/19/07
Posts: 36
From: California

Did you get your error resolved? I was wondering if you tried working on all your files out of the same directory located in the HTDOCS folder. Have all your files located in the same directory and don't use any file path to connect to your db_connect.php script use

require_once( 'db_connect.php ')

and see if you can connect to your DB.

wintersdance |     Viewed: 8,875 Times | Reply to This | To top
Viewing Page: 1 of 1

1 |

You must be logged in to post on the forums. Login or Register

"" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy