Php login PLEASE HELP THANKS
Posted: Sat Apr 24, 2010 6:15 pm
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
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>