Jump to content

value is being lost for no reason


jamesxg1

Recommended Posts

Hiya peeps,

 

Heres the snippet of my code.

 

if(ereg("^[^@]{1,64}@[^@]{1,255}$", $levelone)):
$this->levelOneUser = mysql_real_escape_string(trim($levelone));
else:
return 'Registration Failed!';
endif;

$this->levelOneSelectEarnings = "SELECT `earnings`, `refcount` FROM `members` WHERE emailaddress = '$this->levelOneUser' LIMIT 1";
$this->levelOneSelectEarningsSQL = mysql_query($this->levelOneSelectEarnings);

if($this->levelOneSelectEarningsSQL == FALSE):
return 'Registeration failed!';
else:

while($this->earnings = mysql_fetch_assoc($this->levelOneSelectEarningsSQL)):
$this->levelOneSubTotal = $this->earnings['earnings'];
$this->levelOneSubRefCount = $this->earnings['refcount']+1;
endwhile;

$this->levelOneTotal = $this->levelOneSubTotal + 1.00;
$this->levelOneRefCount = $this->levelOneSubRefCount + 1;



     // the var $this->levelOneUser has the correct value until here. And then the value is dropped and i dont know why.




if($this->levelOneSelectReferralSQL == FALSE):
return 'Registeration failed!';
else:

 

Many thanks

 

James.

 

Link to comment
Share on other sites

Since that is not all of the relevant code (for example what did you remove from the posted code that is setting $this->levelOneSelectReferralSQL) it is not possible to tell you what logical error there is in your code that is causing the problem.

 

Also, you do know that you only need to define and use class variables when you need them to be shared between different class methods or accessed in the main code as data object of the instance of the class. You don't need to define and use $this->variable_name for every single variable that is used in a class function.

Link to comment
Share on other sites

Hiya mate,

 

Here's the full code.

 

<?php

class userControl {

private $emailaddress;
private $password;
private $passwordconf;
private $firstname;
private $lastname;
private $housenumber;
private $road;
private $city;
private $county;
private $postcode;
private $refer;
private $levelone;
private $leveltwo;

function registerUser($emailaddress, $password, $passwordconf, $firstname, $lastname, $housenumber, $road, $city, $county, $postcode, $refer) {

if(empty($refer)):
$this->refer = mysql_real_escape_string(trim('----'));
else:

if(ereg("^[^@]{1,64}@[^@]{1,255}$", $refer)):
$this->refer = mysql_real_escape_string(trim($refer));
else:
return 'Registration Failed!';
endif;

endif;

 $postcode = strtoupper(str_replace(" ","",$postcode));

if(eregi("^(GIR0AA)|(TDCU1ZZ)|((([A-PR-UWYZ][0-9][0-9]?)|"."(([A-PR-UWYZ][A-HK-Y][0-9][0-9]?)|"."(([A-PR-UWYZ][0-9][A-HJKSTUW])|"."([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))))"."[0-9][ABD-HJLNP-UW-Z]{2})$", $postcode)):
    $this->postcode = mysql_real_escape_string(trim($postcode));
else:
    return 'Registration Failed!';
endif;

if(ereg("^[^@]{1,64}@[^@]{1,255}$", $emailaddress)):
$this->emailaddress = mysql_real_escape_string(trim($emailaddress));
else:
return 'Registration Failed!';
endif;

if(strlen($password) >= 6 && ereg("[a-z]", $password) && ereg("[0-9]", $password)):
$this->password = base64_encode(md5(sha1(md5(mhash(MHASH_CRC32, $password . '823ehsp2192u')))));
$this->password = mysql_real_escape_string(trim($this->password));
else:
return 'Registration Failed!';
endif;

if(strlen($passwordconf) >= 6 && ereg("[a-z]", $passwordconf) && ereg("[0-9]", $passwordconf)):
$this->passwordconf = base64_encode(md5(sha1(md5(mhash(MHASH_CRC32, $passwordconf . '823ehsp2192u')))));
$this->passwordconf = mysql_real_escape_string(trim($this->passwordconf));
else:
return 'Registration Failed!';
endif;

if(preg_match("/^\d$/", $housenumber)):
return 'Registration Failed!';
else:
$this->housenumber = mysql_real_escape_string(trim($housenumber));
endif;

if(preg_match("/^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$/", $firstname)):
$this->firstname = mysql_real_escape_string(trim($firstname));
else:
return 'Registration Failed!';
endif;

if(preg_match("/^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$/", $lastname)):
$this->lastname = mysql_real_escape_string(trim($lastname));
else:
return 'Registration Failed!';
endif;

if($this->password !== $this->passwordconf):
return 'Registration Failed!';
else:

$this->time = date('H:i:s');
$this->date = date('Y-m-d');
$this->road = mysql_real_escape_string(trim($road));

$this->registerInsert = "INSERT INTO `members` (`emailaddress`, `firstname`, `lastname`, `password`, `housenumber`, `road`, `city`, `county`, `postcode`, `time`, `date`, `refcount`, `earnings`) VALUES('$this->emailaddress', '$this->firstname', '$this->lastname', '$this->password', '$this->housenumber', '$this->road', '$this->city', '$this->county', '$this->postcode', '$this->time', '$this->date', '0', '0')";
$this->referrerInsert = "INSERT INTO `referrals` (`referrer`, `member`, `time`, `date`) VALUES('$this->refer', '$this->emailaddress', '$this->time', '$this->date')";

if(mysql_query($this->registerInsert) == FALSE):
return 'Registeration failed!';
else:

if(mysql_query($this->referrerInsert) == FALSE):
return 'Registeration failed!';
else:

$this->levelOne($this->refer);

endif;
endif;
endif;
}

function levelOne($levelone) {

if(ereg("^[^@]{1,64}@[^@]{1,255}$", $levelone)):
$this->levelOneUser = mysql_real_escape_string(trim($levelone));
else:
return 'Registration Failed!';
endif;

$this->levelOneSelectEarnings = "SELECT `earnings`, `refcount` FROM `members` WHERE emailaddress = '$this->levelOneUser' LIMIT 1";
$this->levelOneSelectEarningsSQL = mysql_query($this->levelOneSelectEarnings);

if($this->levelOneSelectEarningsSQL == FALSE):
return 'Registeration failed!';
else:

while($this->earnings = mysql_fetch_assoc($this->levelOneSelectEarningsSQL)):
$this->levelOneSubTotal = $this->earnings['earnings'];
$this->levelOneSubRefCount = $this->earnings['refcount']+1;
endwhile;

$this->levelOneTotal = $this->levelOneSubTotal + 1.00;
$this->levelOneRefCount = $this->levelOneSubRefCount + 1;


// var being dropped here!.


if($this->levelOneSelectReferralSQL == FALSE):
return 'Registeration failed!';
else:

$this->levelOneSelectReferral = "SELECT `referrer` FROM `referrals` WHERE member = '$this->levelOneUser' LIMIT 1";
$this->levelOneSelectReferralSQL = mysql_query($this->levelOneSelectReferral);

while($this->referrer = mysql_fetch_assoc($this->levelOneSelectReferralSQL)):
$this->referrer = $this->referrer['referrer'];
endwhile;

$this->levelOneInsert = "UPDATE `members` SET earnings = '$this->levelOneTotal', refcount = '$this->levelOneRefCount' WHERE emailaddress = '$this->levelOneUser'";
$this->levelOneInsertSQL = mysql_query($this->levelOneInsert);

if($this->levelOneInsertSQL == FALSE):
return 'Registeration failed!';
else:
$this->leveltwo($this->referrer);
endif;
endif;
endif;
}
?>

 

 

Many thanks

 

James.

Link to comment
Share on other sites

One thing I have noticed is when you are calling

$this->levelOne($this->refer);

The levelOne function has a return but its not assigned or handled by the registerUser function at all..

 

With that said are you sure that its even getting to that part of your levelOne function?

Link to comment
Share on other sites

One thing I have noticed is when you are calling

$this->levelOne($this->refer);

The levelOne function has a return but its not assigned or handled by the registerUser function at all..

 

With that said are you sure that its even getting to that part of your levelOne function?

 

I'm not too sure I got all that lol. But yes the levelOne function gets the $this->refer var.

 

Many thanks

 

James.

Link to comment
Share on other sites

So, you are guessing that the variable in question is being lost because the symptom you see in front of you is the return of the 'Registration failed!' value from the function?

 

LOL, you are testing $this->levelOneSelectReferralSQL before the query that sets it has even been executed, so of course it is a FALSE value.

 

 

Link to comment
Share on other sites

So, you are guessing that the variable in question is being lost because the symptom you see in front of you is the return of the 'Registration failed!' value from the function?

 

LOL, you are testing $this->levelOneSelectReferralSQL before the query that sets it has even been executed, so of course it is a FALSE value.

 

Cheers for that bud, fixed! :). Just wondering I know this is off topic but I have

	$this->levelOneTotal = $this->levelOneSubTotal + 1.00;

but it only inserts as '1' how do I make it insert as 1.00 as I also need to insert as 0.50 on levelTwo once I have created it and 12.05 on levelThree.

 

Many thanks

 

James.

Link to comment
Share on other sites

Most people use return for functions like yours to return true or false..

so then in your main function (registerUser) you will do something like this.

 if ($this->levelOne($this->refer)) { // This is assuming that it returns true on success and false of failure
echo 'Yay it worked';
} else {
echo 'Epic Fail';
}

 

Also.. this line

$this->refer = mysql_real_escape_string(trim('----'));

doesnt need to be that complex because you are defining the value and I dont think you are going to do some sql injection on yourself :P.. I have been wrong before :D

 

EDIT: What is your tables field type that is storing those values?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.