Page 1 of 1

Php login PLEASE HELP THANKS

Posted: Sat Apr 24, 2010 6:15 pm
by hadlawp
I really need help finding the error in my script if someone can please help me, thanks soo much.
And if your are able to get it to work please feel free to use this script, and i did create the correct MySQL table for this.

Thanks in advance!!!! Peter

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title></title>
</head>

<body>
<?php

/*
 
 within the LoginMachine object there is a method and variable
 that contains all the errors from the processing and returns -1
 if there were no errors "anyErrors()"
 
 within the LoginMachine object there is a method that returns
 a boolean if there is an error "getError()", if true: there is
 an error; if false: there is no error
*/


class LoginMachine
{
    var $eUsername = false;
    var $ePassword = false;
    var $eEmail = false;
    var $all = false;
    
    function LoginMachine()
    {}
    
    function db_open()
    {
        $result = mysql_connect("THE CORRECT INFO") or die(mysql_error());
        $result2 = mysql_select_db("THE CORRECT INFO") or die(mysql_error());
    }
    
    function checkForBlanks($results)
    {
        if(!$results['username']||!$results['password1']||!$results['password2']||!$results['fName']||!$results['lName']||!$results['esuffix1']||!$results['esuffix2']){
            $this->all = true;
        }
        else{
            $this->all = false;
        }
    }
    
    function checkUsernameIFINUSE($userN)
    {
        if (!get_magic_quotes_gpc()){
            $userN = addcslashes($userN);
        }
        $useralias = $userN;
        
        $check = mysql_query("SELECT username FROM doneJobDB WHERE username = '$useralias'")or die(mysql_error());
        
        $check2 = mysql_num_rows($check);
        
        if ($check2 != 0){
            $this->eUsername = true;
        }
        else{
            $this->eUsername = false;
        }
        
    }
    
    function checkPasswordsIFMATCH($pass1, $pass2)
    {
        if($pass1==$pass2){
            $this->ePassword = false;
        }
        else{
            $this->ePassword = true;
        }
    }
    
    function checkEmailsIFMATCH($e1, $e2, $es1, $es2)
    {
        if($e1!=$e2||$es1!=$es2){
            $this->eEmail = true;
        }
        else{
            $this->eEmail = false;
        }
    }
    
    function anyErrors()
    {
        if($eUsername||$ePassword||$eEmail||$all){
            return 0;
        }
        else{
            return -1;
        }
    }
    
    function getError($field)
    {
        if($field=="all"){
            return $this->all;
        }
        elseif($field=="username"){
            return $this->eUsername;
        }
        elseif($field=="passwords"){
            return $this->ePassword;
        }
        elseif($field=="email"){
            return $this->eEmail;
        }
        else{
            return false;
        }
    }
    
    function insertDataToDB($all_info)
    {
        $username= $all_info['username'];
        $password= $all_info['password1'];
        $firstName= $all_info['fName'];
        $lastName= $all_info['lName'];
        $email= $all_info['email1'];
        $emailSuffix= $all_info['esuffix1'];
        
        $password = md5($password);
        
        if(!get_magic_quotes_gpc()){
            $password = addslashes($password);
            $username = addslashes($username);
        }
        
        $insert = "INSERT INTO doneJobDB (username, password, firstName, lastName, email, emailSuffix) VALUES ('".$username."', '".$password."', '".$firstName."', '".$lastName."', '".$email."', '".$emailSuffix."')";
        
        $add_member = mysql_query($insert);
        
    }
    
  
}



$thisLogin = new LoginMachine();

//uses the LoginMachine's db_open method to open and connect to the database
$thisLogin->db_open();

//begins by checking if the form has been submitted and then processes the data
if(isset($_POST['submit']))
{
	
	//checks that all fields have been fully filled in
	$thisLogin->checkForBlanks($_POST[]);
	
	//checks if the username is already in use
	$thisLogin->checkUsernameIFINUSE($_POST['username']);
	
	//checks if the two passwords matched
	$thisLogin->checkPasswordsIFMATCH($_POST['password1'], $_POST['password2']);
	
	//checks if the two emails matched
	$thisLogin->checkEmailsIFMATCH($_POST['email1'], $_POST['email2'], $_POST['esuffix1'], $_POST['esuffix2']);
	
	//checks to see if the robot code was matched
	
	$thisLogin->checkForRobot($_POST['hiddenCodeNum']);
	
	//checks if any errors occured, if none INSERTS all of the data to the database
	//if evenone error occurs skips the insertion and the later in HTML creates the form for submittance
	//also if the form has been submitted and some errors occured, prints of which errors occured
	if($thisLogin->anyErrors()==-1){
		$thisLogin->insertDataToDB($_POST[]);
	}
		
}


//first checks once again if the form has been previously submitted
//if it has been, it checks for errors, if any: generates form with error printout; if none: redirects to login pages with success message
if(isset($_POST['submit']))
{

	if($thisLogin->anyErrors()==-1){ //redirect to the login page
		header("Location: Login.php?Reg=Successful");
	}
	
	else //generate the pages with the error printout
	{

		//prints out the Registration title
		echo"<h1>Registration</h1>";
		
		//prints out all of the errors that occured
		echo"<div id=\"errors\">"; //creates a div for the red color font
		
		if($thisLogin->getError("all")){
			echo"*Not all fields have been filled in*<br/>";
		}
		
		if($thisLogin->getError("username")){
			echo"*The usename ".$_POST['username']." is already in use*<br/>";
		}
		
		if($thisLogin->getError("passwords")){
			echo"*The passwords you entered did not match*<br/>";
		}
		
		if($thisLogin->getError("email")){
			echo"*The emails you entered did not match*<br/>";
		}
		
		//if(getError("robot")){
		//	echo"*Are you a \"robot\"?*<br/>";
		//}
		
		echo"</div>";
		
		//creates the form with submit information
		echo"<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
		
		//creates the table for the form
		echo"<table border=\"0\">";
		
		//****************************************************************************************************//
		
		//creates the Username field
		//decides whether to print out the normal color or the feild error color "red"
		if($thisLogin->getError("username")){
			echo"<tr><td><font color=\"red\">*Username:</font></td>";
		}
		
		else{
			echo"<tr><td>Username:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"username\" maxlength=\"60\"></td></tr>";

		//****************************************************************************************************//
		
		//creates the Password fields
		if($thisLogin->getError("passwords")){
			echo"<tr><td><font color=\"red\">*Password:</font></td>";
		}
		
		else{
			echo"<tr><td>Password:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"password1\" maxlength=\"10\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Confirm Password fields
		if($thisLogin->getError("passwords")){
			echo"<tr><td><font color=\"red\">*Confirm Password:</font></td>";
		}
		
		else{
			echo"<tr><td>Confirm Password:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"password2\" maxlength=\"10\"></td></tr>";
	
		//****************************************************************************************************//
		
		//creates the Name Fields
		echo"<tr><td>First Name:</td><td><input type=\"text\" name=\"fName\" maxlength=\"60\">".$_POST['fName']."</td></tr>";
		
		echo"<tr><td>Last Name:</td><td><input type=\"text\" name=\"lName\" maxlength=\"60\">".$_POST['lName']."</td></tr>";
		
		//****************************************************************************************************//
		
		//creates the E-Mail Fields		
		if($thisLogin->getError("email")){
			echo"<tr><td><font color=\"red\">*Email:</font></td>";
		}
		
		else{
			echo"<tr><td>Email:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"email1\" maxlength=\"60\"></td>.<td><input type=\"text\" name=\"esuffix1\" maxlength=\"5\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Confirm E-Mail Fields
		if($thisLogin->getError("email")){
			echo"<tr><td><font color=\"red\">*Confirm Email:</font></td>";
		}
	
		else{
			echo"<tr><td>Confirm Email:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"email2\" maxlength=\"60\"></td>\"dot\"<td><input type=\"text\" name=\"esuffix2\" maxlength=\"5\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Robot Field, to test whether or not someone is a robot
		//this still has to be added
		
		//****************************************************************************************************//
		
		//creates the submit button
		echo"<tr><th colspan=\"3\"><input type=\"submit\" name=\"submit\" value=\"Register\"></th></tr>";
		
		//creates the ending to the table and form
		echo"</table></form>";
		
	}
}

//else prints out the regular form, meaning that the form has not yet been submitted

else
{
		//prints out the Registration title
		echo"<h1>Registration</h1>";
		
		//creates the form with submit information
		echo"<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
		
		//creates the table for the form
		echo"<table border=\"0\">";
		
		//****************************************************************************************************//
		
		//creates the Username field
		echo"<tr><td>Username:</td>";
		
		echo"<td><input type=\"text\" name=\"username\" maxlength=\"60\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Password fields
		echo"<tr><td>Password:</td>";
		
		echo"<td><input type=\"text\" name=\"password1\" maxlength=\"10\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Confirm Password fields
		echo"<tr><td>Confirm Password:</td>";
		
		echo"<td><input type=\"text\" name=\"password2\" maxlength=\"10\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Name Fields
		echo"<tr><td>First Name:</td><td><input type=\"text\" name=\"fName\" maxlength=\"60\"></td></tr>";
		
		echo"<tr><td>Last Name:</td><td><input type=\"text\" name=\"lName\" maxlength=\"60\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the E-Mail Fields		
		echo"<tr><td>Email:</td>";
		
		echo"<td><input type=\"text\" name=\"email1\" maxlength=\"60\">\"dot\"</td><td><input type=\"text\" name=\"esuffix1\" maxlength=\"5\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Confirm E-Mail Fields
		echo"<tr><td>Confirm Email:</td>";
		
		echo"<td><input type=\"text\" name=\"email2\" maxlength=\"60\">\"dot\"</td><td><input type=\"text\" name=\"esuffix2\" maxlength=\"5\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Robot Field, to test whether or not someone is a robot
		//this still has to be added
		
		//****************************************************************************************************//
		
		//creates the submit button
		echo"<tr><th colspan=\"3\"><input type=\"submit\" name=\"submit\" value=\"Register\"></th></tr>";
		
		//creates the ending to the table and form
		echo"</table></form>";
}

?>

</body>
</html>


Re: Php login PLEASE HELP THANKS

Posted: Sat Apr 24, 2010 7:08 pm
by requinix
I'd sure help to know what we were looking for.

Re: Php login PLEASE HELP THANKS

Posted: Sat Apr 24, 2010 7:33 pm
by hadlawp
I really don't know why but this script is having problems, it "white pages" and I cant find what the problem is. Any help possible would be appreciated. I really hope you guys can help.
I believe the error is a compile time error meaning something is not right in the coding, like maybe I am only missing a "}" but I cant find it.

Thanks Peter

Re: Php login PLEASE HELP THANKS

Posted: Sat Apr 24, 2010 8:56 pm
by requinix
PHP lint says nothing's wrong. My IDE only finds one warning (anyErrors() method: those variables need a $this->).

Edit your php.ini and set error_reporting=E_ALL and display_errors=on. Then restart Apache and see what you get.

Re: Php login PLEASE HELP THANKS

Posted: Sat Apr 24, 2010 9:38 pm
by hadlawp
That's right i didnt notice that, I fixed it but it still white screens, and I looked into the php error reporting, and currently I am not running my own server, im hosted somewhere else and they do not allow for editing the php ini file.

After that fix is there any other reason why there might be a problem that you see??

Again thank you so much.
Peter

Heres the fixed code

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
        <title></title>
</head>

<body>
<?php

/*
 
 within the LoginMachine object there is a method and variable
 that contains all the errors from the processing and returns -1
 if there were no errors "anyErrors()"
 
 within the LoginMachine object there is a method that returns
 a boolean if there is an error "getError()", if true: there is
 an error; if false: there is no error
*/


class LoginMachine
{
    var $eUsername = false;
    var $ePassword = false;
    var $eEmail = false;
    var $all = false;
   
    function LoginMachine()
    {}
   
    function db_open()
    {
        $result = mysql_connect("the right info") or die(mysql_error());
        $result2 = mysql_select_db("the right info") or die(mysql_error());
    }
   
    function checkForBlanks($results)
    {
        if(!$results['username']||!$results['password1']||!$results['password2']||!$results['fName']||!$results['lName']||!$results['esuffix1']||!$results['esuffix2']){
            $this->all = true;
        }
        else{
            $this->all = false;
        }
    }
   
    function checkUsernameIFINUSE($userN)
    {
        if (!get_magic_quotes_gpc()){
            $userN = addcslashes($userN);
        }
        $useralias = $userN;
       
        $check = mysql_query("SELECT username FROM doneJobDB WHERE username = '$useralias'")or die(mysql_error());
       
        $check2 = mysql_num_rows($check);
       
        if ($check2 != 0){
            $this->eUsername = true;
        }
        else{
            $this->eUsername = false;
        }
       
    }
   
    function checkPasswordsIFMATCH($pass1, $pass2)
    {
        if($pass1==$pass2){
            $this->ePassword = false;
        }
        else{
            $this->ePassword = true;
        }
    }
   
    function checkEmailsIFMATCH($e1, $e2, $es1, $es2)
    {
        if($e1!=$e2||$es1!=$es2){
            $this->eEmail = true;
        }
        else{
            $this->eEmail = false;
        }
    }
   
    function anyErrors()
    {
        if($this->eUsername||$this->ePassword||$this->eEmail||$this->all){
            return 0;
        }
        else{
            return -1;
        }
    }
   
    function getError($field)
    {
        if($field=="all"){
            return $this->all;
        }
        elseif($field=="username"){
            return $this->eUsername;
        }
        elseif($field=="passwords"){
            return $this->ePassword;
        }
        elseif($field=="email"){
            return $this->eEmail;
        }
        else{
            return false;
        }
    }
   
    function insertDataToDB($all_info)
    {
        $username= $all_info['username'];
        $password= $all_info['password1'];
        $firstName= $all_info['fName'];
        $lastName= $all_info['lName'];
        $email= $all_info['email1'];
        $emailSuffix= $all_info['esuffix1'];
       
        $password = md5($password);
       
        if(!get_magic_quotes_gpc()){
            $password = addslashes($password);
            $username = addslashes($username);
        }
       
        $insert = "INSERT INTO doneJobDB (username, password, firstName, lastName, email, emailSuffix) VALUES ('".$username."', '".$password."', '".$firstName."', '".$lastName."', '".$email."', '".$emailSuffix."')";
       
        $add_member = mysql_query($insert);
       
    }
   
 
}



$thisLogin = new LoginMachine();

//uses the LoginMachine's db_open method to open and connect to the database
$thisLogin->db_open();

//begins by checking if the form has been submitted and then processes the data
if(isset($_POST['submit']))
{
       
        //checks that all fields have been fully filled in
        $thisLogin->checkForBlanks($_POST[]);
       
        //checks if the username is already in use
        $thisLogin->checkUsernameIFINUSE($_POST['username']);
       
        //checks if the two passwords matched
        $thisLogin->checkPasswordsIFMATCH($_POST['password1'], $_POST['password2']);
       
        //checks if the two emails matched
        $thisLogin->checkEmailsIFMATCH($_POST['email1'], $_POST['email2'], $_POST['esuffix1'], $_POST['esuffix2']);
       
        //checks to see if the robot code was matched
       
        $thisLogin->checkForRobot($_POST['hiddenCodeNum']);
       
        //checks if any errors occured, if none INSERTS all of the data to the database
        //if evenone error occurs skips the insertion and the later in HTML creates the form for submittance
        //also if the form has been submitted and some errors occured, prints of which errors occured
        if($thisLogin->anyErrors()==-1){
                $thisLogin->insertDataToDB($_POST[]);
        }
               
}


//first checks once again if the form has been previously submitted
//if it has been, it checks for errors, if any: generates form with error printout; if none: redirects to login pages with success message
if(isset($_POST['submit']))
{

        if($thisLogin->anyErrors()==-1){ //redirect to the login page
                header("Location: Login.php?Reg=Successful");
        }
       
        else //generate the pages with the error printout
        {

                //prints out the Registration title
                echo"<h1>Registration</h1>";
               
                //prints out all of the errors that occured
                echo"<div id=\"errors\">"; //creates a div for the red color font
               
                if($thisLogin->getError("all")){
                        echo"*Not all fields have been filled in*<br/>";
                }
               
                if($thisLogin->getError("username")){
                        echo"*The usename ".$_POST['username']." is already in use*<br/>";
                }
               
                if($thisLogin->getError("passwords")){
                        echo"*The passwords you entered did not match*<br/>";
                }
               
                if($thisLogin->getError("email")){
                        echo"*The emails you entered did not match*<br/>";
                }
               
                //if(getError("robot")){
                //      echo"*Are you a \"robot\"?*<br/>";
                //}
               
                echo"</div>";
               
                //creates the form with submit information
                echo"<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
               
                //creates the table for the form
                echo"<table border=\"0\">";
               
                //****************************************************************************************************//
               
                //creates the Username field
                //decides whether to print out the normal color or the feild error color "red"
                if($thisLogin->getError("username")){
                        echo"<tr><td><font color=\"red\">*Username:</font></td>";
                }
               
                else{
                        echo"<tr><td>Username:</td>";
                }
               
                echo"<td><input type=\"text\" name=\"username\" maxlength=\"60\"></td></tr>";

                //****************************************************************************************************//
               
                //creates the Password fields
                if($thisLogin->getError("passwords")){
                        echo"<tr><td><font color=\"red\">*Password:</font></td>";
                }
               
                else{
                        echo"<tr><td>Password:</td>";
                }
               
                echo"<td><input type=\"text\" name=\"password1\" maxlength=\"10\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the Confirm Password fields
                if($thisLogin->getError("passwords")){
                        echo"<tr><td><font color=\"red\">*Confirm Password:</font></td>";
                }
               
                else{
                        echo"<tr><td>Confirm Password:</td>";
                }
               
                echo"<td><input type=\"text\" name=\"password2\" maxlength=\"10\"></td></tr>";
       
                //****************************************************************************************************//
               
                //creates the Name Fields
                echo"<tr><td>First Name:</td><td><input type=\"text\" name=\"fName\" maxlength=\"60\">".$_POST['fName']."</td></tr>";
               
                echo"<tr><td>Last Name:</td><td><input type=\"text\" name=\"lName\" maxlength=\"60\">".$_POST['lName']."</td></tr>";
               
                //****************************************************************************************************//
               
                //creates the E-Mail Fields            
                if($thisLogin->getError("email")){
                        echo"<tr><td><font color=\"red\">*Email:</font></td>";
                }
               
                else{
                        echo"<tr><td>Email:</td>";
                }
               
                echo"<td><input type=\"text\" name=\"email1\" maxlength=\"60\"></td>.<td><input type=\"text\" name=\"esuffix1\" maxlength=\"5\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the Confirm E-Mail Fields
                if($thisLogin->getError("email")){
                        echo"<tr><td><font color=\"red\">*Confirm Email:</font></td>";
                }
       
                else{
                        echo"<tr><td>Confirm Email:</td>";
                }
               
                echo"<td><input type=\"text\" name=\"email2\" maxlength=\"60\"></td>\"dot\"<td><input type=\"text\" name=\"esuffix2\" maxlength=\"5\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the Robot Field, to test whether or not someone is a robot
                //this still has to be added
               
                //****************************************************************************************************//
               
                //creates the submit button
                echo"<tr><th colspan=\"3\"><input type=\"submit\" name=\"submit\" value=\"Register\"></th></tr>";
               
                //creates the ending to the table and form
                echo"</table></form>";
               
        }
}

//else prints out the regular form, meaning that the form has not yet been submitted

else
{
                //prints out the Registration title
                echo"<h1>Registration</h1>";
               
                //creates the form with submit information
                echo"<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
               
                //creates the table for the form
                echo"<table border=\"0\">";
               
                //****************************************************************************************************//
               
                //creates the Username field
                echo"<tr><td>Username:</td>";
               
                echo"<td><input type=\"text\" name=\"username\" maxlength=\"60\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the Password fields
                echo"<tr><td>Password:</td>";
               
                echo"<td><input type=\"text\" name=\"password1\" maxlength=\"10\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the Confirm Password fields
                echo"<tr><td>Confirm Password:</td>";
               
                echo"<td><input type=\"text\" name=\"password2\" maxlength=\"10\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the Name Fields
                echo"<tr><td>First Name:</td><td><input type=\"text\" name=\"fName\" maxlength=\"60\"></td></tr>";
               
                echo"<tr><td>Last Name:</td><td><input type=\"text\" name=\"lName\" maxlength=\"60\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the E-Mail Fields            
                echo"<tr><td>Email:</td>";
               
                echo"<td><input type=\"text\" name=\"email1\" maxlength=\"60\">\"dot\"</td><td><input type=\"text\" name=\"esuffix1\" maxlength=\"5\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the Confirm E-Mail Fields
                echo"<tr><td>Confirm Email:</td>";
               
                echo"<td><input type=\"text\" name=\"email2\" maxlength=\"60\">\"dot\"</td><td><input type=\"text\" name=\"esuffix2\" maxlength=\"5\"></td></tr>";
               
                //****************************************************************************************************//
               
                //creates the Robot Field, to test whether or not someone is a robot
                //this still has to be added
               
                //****************************************************************************************************//
               
                //creates the submit button
                echo"<tr><th colspan=\"3\"><input type=\"submit\" name=\"submit\" value=\"Register\"></th></tr>";
               
                //creates the ending to the table and form
                echo"</table></form>";
}

?>

</body>
</html>

Re: Php login PLEASE HELP THANKS

Posted: Sat Apr 24, 2010 9:58 pm
by hadlawp
I was able to get error reporting to work, so now i can see what some errors are:

I modified the code to fix some of the errors but then I got stuck at this error:

Parse error: syntax error, unexpected '$', expecting '&' or T_VARIABLE in ***** on line 38

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title></title>
</head>

<body>
<?php

/*
 
 within the LoginMachine object there is a method and variable
 that contains all the errors from the processing and returns -1
 if there were no errors "anyErrors()"
 
 within the LoginMachine object there is a method that returns
 a boolean if there is an error "getError()", if true: there is
 an error; if false: there is no error
*/


class LoginMachine
{
    var $eUsername = false;
    var $ePassword = false;
    var $eEmail = false;
    var $all = false;
    
    function LoginMachine()
    {}
    
    function db_open()
    {
        $result = mysql_connect("the correct info") or die(mysql_error());
        $result2 = mysql_select_db("tci") or die(mysql_error());
    }
    
    function checkForBlanks($1,$2,$3,$4,$5,$6,$7,$8,$9)
    {
        if(!$1||!$3||!$4||!$5||!$6||!$7||!$8||!$9){
            $this->all = true;
        }
        else{
            $this->all = false;
        }
    }
    
    function checkUsernameIFINUSE($userN)
    {
        if (!get_magic_quotes_gpc()){
            $userN = addcslashes($userN);
        }
        $useralias = $userN;
        
        $check = mysql_query("SELECT username FROM doneJobDB WHERE username = '$useralias'")or die(mysql_error());
        
        $check2 = mysql_num_rows($check);
        
        if ($check2 != 0){
            $this->eUsername = true;
        }
        else{
            $this->eUsername = false;
        }
        
    }
    
    function checkPasswordsIFMATCH($pass1, $pass2)
    {
        if($pass1==$pass2){
            $this->ePassword = false;
        }
        else{
            $this->ePassword = true;
        }
    }
    
    function checkEmailsIFMATCH($e1, $e2, $es1, $es2)
    {
        if($e1!=$e2||$es1!=$es2){
            $this->eEmail = true;
        }
        else{
            $this->eEmail = false;
        }
    }
    
    function anyErrors()
    {
        if($eUsername||$ePassword||$eEmail||$all){
            return 0;
        }
        else{
            return -1;
        }
    }
    
    function getError($field)
    {
        if($field=="all"){
            return $this->all;
        }
        elseif($field=="username"){
            return $this->eUsername;
        }
        elseif($field=="passwords"){
            return $this->ePassword;
        }
        elseif($field=="email"){
            return $this->eEmail;
        }
        else{
            return false;
        }
    }
    
    function insertDataToDB($all_info)
    {
        $username= $all_info['username'];
        $password= $all_info['password1'];
        $firstName= $all_info['fName'];
        $lastName= $all_info['lName'];
        $email= $all_info['email1'];
        $emailSuffix= $all_info['esuffix1'];
        
        $password = md5($password);
        
        if(!get_magic_quotes_gpc()){
            $password = addslashes($password);
            $username = addslashes($username);
        }
        
        $insert = "INSERT INTO doneJobDB (username, password, firstName, lastName, email, emailSuffix) VALUES ('".$username."', '".$password."', '".$firstName."', '".$lastName."', '".$email."', '".$emailSuffix."')";
        
        $add_member = mysql_query($insert);
        
    }
    
  
}



$thisLogin = new LoginMachine();

//uses the LoginMachine's db_open method to open and connect to the database
$thisLogin->db_open();

//begins by checking if the form has been submitted and then processes the data
if(isset($_POST['submit']))
{
	$1 = '".$_POST['username']."';
	$2 = '".$_POST['password1']."';
	$3 = '".$_POST['password2']."';
	$4 = '".$_POST['fName']."';
	$5 = '".$_POST['lName']."';
	$6 = '".$_POST['email1']."';
	$7 = '".$_POST['esuffix1']."';
	$8 = '".$_POST['email2']."';
	$9 = '".$_POST['esuffix2']."';
	
	//checks that all fields have been fully filled in
	$thisLogin->checkForBlanks($1, $2, $3, $4, $5, $6, $7, $8, $9);
	
	//checks if the username is already in use
	$thisLogin->checkUsernameIFINUSE($_POST['username']);
	
	//checks if the two passwords matched
	$thisLogin->checkPasswordsIFMATCH($_POST['password1'], $_POST['password2']);
	
	//checks if the two emails matched
	$thisLogin->checkEmailsIFMATCH($_POST['email1'], $_POST['email2'], $_POST['esuffix1'], $_POST['esuffix2']);
	
	//checks to see if the robot code was matched
	
	$thisLogin->checkForRobot($_POST['hiddenCodeNum']);
	
	//checks if any errors occured, if none INSERTS all of the data to the database
	//if evenone error occurs skips the insertion and the later in HTML creates the form for submittance
	//also if the form has been submitted and some errors occured, prints of which errors occured
	if($thisLogin->anyErrors()==-1){
		$thisLogin->insertDataToDB($_POST[]);
	}
		
}


//first checks once again if the form has been previously submitted
//if it has been, it checks for errors, if any: generates form with error printout; if none: redirects to login pages with success message
if(isset($_POST['submit']))
{

	if($thisLogin->anyErrors()==-1){ //redirect to the login page
		header("Location: Login.php?Reg=Successful");
	}
	
	else //generate the pages with the error printout
	{

		//prints out the Registration title
		echo"<h1>Registration</h1>";
		
		//prints out all of the errors that occured
		echo"<div id=\"errors\">"; //creates a div for the red color font
		
		if($thisLogin->getError("all")){
			echo"*Not all fields have been filled in*<br/>";
		}
		
		if($thisLogin->getError("username")){
			echo"*The usename ".$_POST['username']." is already in use*<br/>";
		}
		
		if($thisLogin->getError("passwords")){
			echo"*The passwords you entered did not match*<br/>";
		}
		
		if($thisLogin->getError("email")){
			echo"*The emails you entered did not match*<br/>";
		}
		
		//if(getError("robot")){
		//	echo"*Are you a \"robot\"?*<br/>";
		//}
		
		echo"</div>";
		
		//creates the form with submit information
		echo"<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
		
		//creates the table for the form
		echo"<table border=\"0\">";
		
		//****************************************************************************************************//
		
		//creates the Username field
		//decides whether to print out the normal color or the feild error color "red"
		if($thisLogin->getError("username")){
			echo"<tr><td><font color=\"red\">*Username:</font></td>";
		}
		
		else{
			echo"<tr><td>Username:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"username\" maxlength=\"60\"></td></tr>";

		//****************************************************************************************************//
		
		//creates the Password fields
		if($thisLogin->getError("passwords")){
			echo"<tr><td><font color=\"red\">*Password:</font></td>";
		}
		
		else{
			echo"<tr><td>Password:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"password1\" maxlength=\"10\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Confirm Password fields
		if($thisLogin->getError("passwords")){
			echo"<tr><td><font color=\"red\">*Confirm Password:</font></td>";
		}
		
		else{
			echo"<tr><td>Confirm Password:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"password2\" maxlength=\"10\"></td></tr>";
	
		//****************************************************************************************************//
		
		//creates the Name Fields
		echo"<tr><td>First Name:</td><td><input type=\"text\" name=\"fName\" maxlength=\"60\">".$_POST['fName']."</td></tr>";
		
		echo"<tr><td>Last Name:</td><td><input type=\"text\" name=\"lName\" maxlength=\"60\">".$_POST['lName']."</td></tr>";
		
		//****************************************************************************************************//
		
		//creates the E-Mail Fields		
		if($thisLogin->getError("email")){
			echo"<tr><td><font color=\"red\">*Email:</font></td>";
		}
		
		else{
			echo"<tr><td>Email:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"email1\" maxlength=\"60\"></td>.<td><input type=\"text\" name=\"esuffix1\" maxlength=\"5\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Confirm E-Mail Fields
		if($thisLogin->getError("email")){
			echo"<tr><td><font color=\"red\">*Confirm Email:</font></td>";
		}
	
		else{
			echo"<tr><td>Confirm Email:</td>";
		}
		
		echo"<td><input type=\"text\" name=\"email2\" maxlength=\"60\"></td>\"dot\"<td><input type=\"text\" name=\"esuffix2\" maxlength=\"5\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Robot Field, to test whether or not someone is a robot
		//this still has to be added
		
		//****************************************************************************************************//
		
		//creates the submit button
		echo"<tr><th colspan=\"3\"><input type=\"submit\" name=\"submit\" value=\"Register\"></th></tr>";
		
		//creates the ending to the table and form
		echo"</table></form>";
		
	}
}

//else prints out the regular form, meaning that the form has not yet been submitted

else
{
		//prints out the Registration title
		echo"<h1>Registration</h1>";
		
		//creates the form with submit information
		echo"<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
		
		//creates the table for the form
		echo"<table border=\"0\">";
		
		//****************************************************************************************************//
		
		//creates the Username field
		echo"<tr><td>Username:</td>";
		
		echo"<td><input type=\"text\" name=\"username\" maxlength=\"60\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Password fields
		echo"<tr><td>Password:</td>";
		
		echo"<td><input type=\"text\" name=\"password1\" maxlength=\"10\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Confirm Password fields
		echo"<tr><td>Confirm Password:</td>";
		
		echo"<td><input type=\"text\" name=\"password2\" maxlength=\"10\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Name Fields
		echo"<tr><td>First Name:</td><td><input type=\"text\" name=\"fName\" maxlength=\"60\"></td></tr>";
		
		echo"<tr><td>Last Name:</td><td><input type=\"text\" name=\"lName\" maxlength=\"60\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the E-Mail Fields		
		echo"<tr><td>Email:</td>";
		
		echo"<td><input type=\"text\" name=\"email1\" maxlength=\"60\">\"dot\"</td><td><input type=\"text\" name=\"esuffix1\" maxlength=\"5\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Confirm E-Mail Fields
		echo"<tr><td>Confirm Email:</td>";
		
		echo"<td><input type=\"text\" name=\"email2\" maxlength=\"60\">\"dot\"</td><td><input type=\"text\" name=\"esuffix2\" maxlength=\"5\"></td></tr>";
		
		//****************************************************************************************************//
		
		//creates the Robot Field, to test whether or not someone is a robot
		//this still has to be added
		
		//****************************************************************************************************//
		
		//creates the submit button
		echo"<tr><th colspan=\"3\"><input type=\"submit\" name=\"submit\" value=\"Register\"></th></tr>";
		
		//creates the ending to the table and form
		echo"</table></form>";
}

?>

</body>
</html>

Re: Php login PLEASE HELP THANKS

Posted: Sat Apr 24, 2010 10:02 pm
by requinix
"1" is not a valid variable name. It must start with a letter or underscore.

You also do it around lines 152-160.

Re: Php login PLEASE HELP THANKS

Posted: Sat Apr 24, 2010 10:30 pm
by hadlawp
Actually I would just like to thank you, because I went through my errors and I was able to get it to work, but you gave me hope. Sounds weird I know, but thanks again.

This has been solved.

Thanks, Peter