Ansego Posted March 17, 2014 Share Posted March 17, 2014 Hi guys, Purpose of flag: Lets me know when all validations have been done and passed before I enter data into the database. Having some troubles trying to increment a value: protected $FlagCount; public function set_FlagCount(){ //self::$counter++; $this->FlagCount++; //return $this; } public function get_FlagCount(){ return $this->FlagCount; } // FULL NAME public function set_FullName($sFullName){ if (preg_replace("/[^A-Za-z\s]/", "", $sFullName) == $sFullName && filter_var($sFullName, FILTER_SANITIZE_STRING) && strlen($sFullName) >= 2) { $FullName = filter_var($sFullName, FILTER_SANITIZE_STRING); $this->set_FlagCount(); $this->FlagCount++; $this->FlagCount = $this->FlagCount + 1; return true; } else { return false; } } Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 17, 2014 Share Posted March 17, 2014 Hi Guy, What's the problem? Quote Link to comment Share on other sites More sharing options...
Ansego Posted March 17, 2014 Author Share Posted March 17, 2014 Hi. I am trying to increment FlagCount but am not having any luck. Been trying for the last few hours and has driven me crazy. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 17, 2014 Share Posted March 17, 2014 If you are instantiating an object of a class that contains those functions then upon calling set_FullName() if the if condition evaluates to true then the object var $this->FlagCount will be incremented 3 times. You haven't shown enough code or where you are attempting to see $this->FlagCount and it has not been incremented. Quote Link to comment Share on other sites More sharing options...
Ansego Posted March 18, 2014 Author Share Posted March 18, 2014 Hi. What I am trying to achieve here is a count; IF the method was successful increment by 1. So If I check Name passed; flag + 1 | Email passed; flag + 1 and so on throughout the checks. The count should ie be 10 and then the flag is to tell me that all fields have passed their checks then go to the next stage of INSERT into the db. But I am unable to get a simple counter system to work. // AUTO LOAD SEEK.INC CLASS function __autoload($classname) { $filename = "./inc/". $classname .".inc"; include_once($filename); } $Seek = new seek(); // COLLECTING AND SETTING VARIBLES if (isset($_POST['Fullname'])) { $sFullName = $_POST['Fullname']; } else { $sFullName = ""; } if (isset($_POST['Email'])){ $sEmail = $_POST['Email']; } else { $sEmail = ""; } // TEST echo "FCNT:" . $Seek->get_FlagCount(); echo " CNT" . seek::$counter; <em class="frmreq"><?php if ($Seek->set_FullName($sFullName) == false && isset($_POST["seek_legalaid"])){ echo "Required!"; } ?></em> <input class="FormFieldInput" type="text" name="Fullname" id="Fullname" placeholder=" Full Name" value="<?php if (isset($_POST["Fullname"])) { echo $_POST["Fullname"]; }; ?>"/> <em class="frmreq"><?php if ($Seek->set_Email($sEmail) == false && isset($_POST["seek_legalaid"])){ echo "Required!"; } ?></em> <input class="FormFieldInput" type="text" name="Email" id="Email" placeholder=" Email" value="<?php if (isset($_POST["Email"])) { echo $_POST["Email"]; }; ?>" /> protected $FlagCount; public static $counter = 0; protected $Testing; // ++++++++++++++++++++++++++++++++++++++++++++++++ CONSTRUCT public function __construct() { $this->set_FlagCount(); //echo "Seek class successfuly!"; //$FlagCount = 1; //self::$counter++; //new seek(); //new seek(); } // FULL NAME public function set_FullName($sFullName){ if (preg_replace("/[^A-Za-z\s]/", "", $sFullName) == $sFullName && filter_var($sFullName, FILTER_SANITIZE_STRING) && strlen($sFullName) >= 2) { $FullName = filter_var($sFullName, FILTER_SANITIZE_STRING); $this->set_FlagCount(); // TEST $this->FlagCount++; // TEST $this->FlagCount = $this->FlagCount + 1; // TEST return true; } else { return false; } } public function get_FullName(){ return $this->Fullname; } // EMAIL public function set_Email($sEmail){ if (filter_var($sEmail, FILTER_VALIDATE_EMAIL) && filter_var($sEmail, FILTER_SANITIZE_EMAIL)){ $Email = filter_var($sEmail, FILTER_SANITIZE_EMAIL); $this->set_FlagCount(); // TEST $this->FlagCount++; // TEST $this->FlagCount = $this->FlagCount + 1; // TEST return true; } else { return false; } //$this->Email = $sEmail; //return $this; } public function get_Email(){ return $this->Email; } Quote Link to comment Share on other sites More sharing options...
Solution Ansego Posted March 18, 2014 Author Solution Share Posted March 18, 2014 (edited) All good, went old school on it; Did not fix the problem but was a solution. I am curious why one is unable to jump from method to method and share a variable... $flagcnt = 0; if ($Seek->set_FullName($sFullName) == true){$flagcnt = $flagcnt + 1;} if ($Seek->set_Email($sEmail) == true){$flagcnt = $flagcnt + 1;} ... ... ... ... ... if ($flagcnt == 7){$Seek->dbsql();} Edited March 18, 2014 by Ansego Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.