Augury Posted February 9, 2014 Share Posted February 9, 2014 I need the class to -- I've got a php which I can't get to print my errors. I'm glad I have errors. I want you to see them. There is one class (the extends is worthless), the rest is functions. HTML is coming from the the bottom block. There are var_dumps. First one should be the error message. Second should be the accepted crap you typed in... http://campkojak.com/form5.php <html> <body> <?php session_start(); class Member { public function __construct() { $member = array('id'=>'', 'usertype'=>'', 'username'=>'', 'email'=>'', 'pass'=>'', 'firstname'=>'', 'lastname'=>'', 'validation_code'=>'', 'address'=>'', 'city'=>'', 'state'=>'', 'zipcode'=>'', 'flag'=>''); //public $member = array_fill_keys($mymember, '') $member[2] = 'entryErr'; $member['username'][4] = $member['email'][4] = $member['firstname'][4] = $member['lastname'][4] = 'required'; } } class NoobMember extends Member { private $hasErr = NULL; private $postmember = NULL; private $member = NULL; private $logmein = NULL; public function getMember() { return $this->member; } public function gethasErr() { return $this->hasErr; } function PostData() { $postmember = $_POST; //$member = $_POST; //var_dump($member); $some = array(); //$membererror = self::BiancaData($member, $some); //$hasErr = array (); //$member_keys = array_keys($member); $member = self::MemberDataCheck($postmember, $hasErr); //return $hasErr; var_dump($hasErr); var_dump($member); } function MemberDataCheck (&$member, &$hasErr) { echo 'member data check'; try { $atributestable = new PDO('mysql:host=localhost;dbname=MemberDB', 'root', 'n58wssp91fns'); } catch (Exception $e) { echo "Unable to connect: " . $e->getMessage() ."<p>"; } $sth = $atributestable->prepare("SELECT member_keys, required FROM AtributesT;"); $sth->execute(); $sth->bindColumn('member_keys', $memkey); $sth->bindColumn('required', $reqval); $req = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $required[$memkey] = $reqval; } $sth = $atributestable->prepare("SELECT member_keys, errmessage FROM AtributesT;"); $sth->execute(); $sth->bindColumn('member_keys', $memkey); $sth->bindColumn('errmessage', $errval); $req = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $errmessage[$memkey] = $errval; } $sth = $atributestable->prepare("SELECT member_keys, regxfilter FROM AtributesT;"); $sth->execute(); $sth->bindColumn('member_keys', $memkey); $sth->bindColumn('regxfilter', $regxval); $req = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $regxfilter[$memkey] = $regxval; } $sth = $atributestable->prepare("SELECT member_keys, submitform FROM AtributesT;"); $sth->execute(); $sth->bindColumn('member_keys', $memkey); $sth->bindColumn('formsubmit', $fsv); $formsubmit = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $formsubit[$memkey] = $fsv; } $some = array(); $hasError = self::BiancaData($member, $some); $member_keys = array_keys($member); foreach ($member_keys as $k) { if (empty($_POST[$k])) { if (($required[$k] <> 'false') || $required[$k] == 'not required' || $required[$k] == NULL) { $hasErr[$k] = 'REQUIRED FEILD'; } else { $hasErr[$k] = NULL; $member[$k][0] ='';} } else { switch($k) { case $k === ('username' || 'firstname' || 'lastname'): if (!preg_match("/^[a-zA-Z ]*$/",$_POST[$k])) { $hasErr[$k] = "may only contain letters, numbers, spaces and hyphen"; $_POST[$k] = ""; $member[$k] = ""; } else { $member[$k][0] = $_POST[$k];} break; case $k === 'email': $member[$k][0] = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL); $hasErr[$k] = "not a vaild e-mail address"; $_POST[$k] = ""; $member[$k] = ""; break; default: if (!preg_match("/^[a-zA-Z ]*$/",$_POST[$k])) { $hasErr[$k] = "may only contain letters, numbers, spaces and hyphen"; $_POST[$k] = ""; $member[$k] = ""; } else { $member[$k][0] = $_POST[$k];} break; } if ($regxfilter[$k]) { if (!preg_match("$regxfilter",$_POST[$k])) { $hasErr[$k] = "may only contain letters, numbers, spaces and hyphen"; $_POST[$k] = ""; $member[$k] = ""; } else { $member[$k][0] = $_POST[$k];} } } } return $member; } function MemberLogin () { if ($hasErr == NULL) { try { $atributestable = new PDO('mysql:host=localhost;dbname=MemberDB', 'root', 'n58wssp91fns'); } catch (Exception $e) { echo "Unable to connect: " . $e->getMessage() ."<p>"; } $sth = $atributestable->prepare("SELECT username, email FROM MemberT;"); $sth->execute(); $sth->bindColumn('username', $users); $sth->bindColumn('email', $em); $sth->bindColumn('password', $pass); $req = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $username[$users] = $password; $email[$em] = $password; } if ($_POST['$username']) { $logmein = password_verify($_POST['pass'], $username[$_POST[$username]]); } if ($_POST['$email']) { $logmein = password_verify($_POST['pass'], $username[$_POST[$username]]); } return $logmein; } } function BiancaData ($mymember, $yourmember) { $mymember_keys = array_keys($mymember); $yourmember_values = array_values($yourmember); foreach ($mymember_keys as $i) { $themember = array ('$i' => '$yourmember_values[$i]'); } return $themember; } } function BiancaDataDefault ($mymember, $yourmember) { $mymember_keys = array_keys($mymember); $yourmember_values = array_values($yourmember); for ($i = 0; $i <= count($mymember) - 1; $i++) { $themember[$mymember_keys[$i]] = $yourmember_values[$mymember_keys[$i]]; if (!$themember[$mymember_keys[$i]]) {$themember[$mymember_keys[$i]] = $mymember[$mymember_keys[$i]];} return $themember; } } function MemberFormType ($FormTYPE) { switch ($FormTYPE) { case login: $noob = new NoobMember; $noob->PostData(); brake; case register: $noob = new NoobMember; if ($noob->PostData()) { $formaction = 'echo htmlspecialchars($_SERVER["PHP_SELF"])'; echo "FUCK"; } else { echo "CONGRADULATIONS"; } brake; case forgotpassword: brake; case edit5: brake; } } function MemberHTMLone () { $FLine[0] = array('Your e-mail Address', 'text', 'email'); $FLine[1] = array('Choose Your Login Name', 'text', 'login'); $FLine[2] = array('Your Site Password', 'text', 'password'); echo ' <table>'; echo ' <p><span class="error">* required field.</span></p>'; for ($m = 0; $m <= count($FLine) - 1; $m++) { echo '<tr><th>' , $FLine[$m][0] , '</th><th><input type="' , $FLine[$m][1] , '" name="' , $FLine[$m][2] , '" value="' , $member[$FLine[$m][2]] , '"></th><th><span class="error">' , $hasError[$FLine[$m][2]] , '</span><br></th></tr>'; } } $noob = new NoobMember; //$noob->PostData(); //var_dump(each($_POST)); //var_dump($_POST); //print_r($_POST); $noob = new NoobMember; $noob->PostData() ?> <h2>Website Registration</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <table> <tr><th>Your e-mail Address</th> <th> <input type="text" name="email" value="<?php echo ''; $noob->getMember(); echo $member['email'];?>"></th> <th><span class="error">* <?php echo $hasErr['email'];?></span><br></th> </tr> <tr><th>Choose Your Login Name</th> <th> <input type="text" name="username" value="<?php echo $member['username'];?>"></th> <th><span class="error">* <?php echo $loginErr;?></span> <br></th> </tr> <tr><th>Your Site Password</th> <th><input type="text" name="password" value="<?php echo $member['password'];?>"></th> <th><span class="error">* <?php echo $passwordErr;?></span><br></th> </tr> <tr><th><input type="submit" name="submit" value="Submit"></th></tr> </table> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
phpzer Posted February 16, 2014 Share Posted February 16, 2014 If I understood correctly <?php error_reporting(E_ALL); ini_set("display_errors", 1); ?> Quote Link to comment Share on other sites More sharing options...
jcbones Posted February 17, 2014 Share Posted February 17, 2014 405 -> 421 break; var_dump($this->hasErr); //$hasErr is a class property, not a function variable. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 17, 2014 Share Posted February 17, 2014 there's so much wrong with this code, both with the php usage and the OOP usage, it will take writing a book to help with it. and since books have been written that cover the basics, the OP needs to go and learn the basics of php coding, then get up to speed with php OOP, then define and start over with this code. the OOP section of the php.net documentation would be the minimum you need to study to get up to speed using or writing php OOP - http://us2.php.net/oop Quote Link to comment Share on other sites More sharing options...
Augury Posted February 21, 2014 Author Share Posted February 21, 2014 (edited) Sheesh, the BB said I had no views. If I understood correctly <?php error_reporting(E_ALL); ini_set("display_errors", 1); ?> Yeah the, um, errors. I haven't been formally educated in this language. I need to add that code again. 405 -> 421 break; var_dump($this->hasErr); //$hasErr is a class property, not a function variable. My debuggin' ain't perfect. I've broken through some of what was holding me back. The $_SESSION article in particular. Man did I try to hammer that class back in though. Anyways, with the input retention secured, I've been breaking into modules. I prefer to deal with a solidified page reference anyways. I imagine I could always sed-for-pussies some hot html with an external application, static or otherwise. Code for NoobMem ber.php, register.php, login.php... It won't log you in yet, this is loosely bound so far. a links http://campkojak.com/ck/register.php login.php http://campkojak.com/ck/NoobMember.php <html> <body> <?php $email = $username = $password = $firstname = $lastname = $homephone = $address = $address2 = $city = $state = $zip = $cellphone = $submit = $Routed = NULL; session_start(); class Member { public function __construct() { $member = array('id'=>'', 'usertype'=>'', 'username'=>'', 'email'=>'', 'pass'=>'', 'firstname'=>'', 'lastname'=>'', 'validation_code'=>'', 'address'=>'', 'city'=>'', 'state'=>'', 'zipcode'=>'', 'flag'=>''); //public $member = array_fill_keys($mymember, '') $member[2] = 'entryErr'; $member['username'][4] = $member['email'][4] = $member['firstname'][4] = $member['lastname'][4] = 'required'; } } class NoobMember extends Member { private $hasErr = NULL; private $postmember = NULL; private $member = NULL; private $logmein = NULL; function PostData() { $postmember = $_POST; $some = array(); $member = self::MemberDataCheck($postmember, $hasErr); $_SESSION['field'] = $member; $_SESSION['hasErr'] = $hasErr; var_dump($hasErr); var_dump($member); session_write_close(); echo '<br><br> heres session'; var_dump($_SESSION); if (empty($hasErr)) { self::MemberRouter($member['submit']); } else { self::MemberRouter('routeback'); } } function MemberDataCheck (&$member, &$hasErr) { echo 'member data check'; try { $atributestable = new PDO('mysql:host=localhost;dbname=MemberDB', 'root', 'PASSWORD HERE'); } catch (Exception $e) { echo "Unable to connect: " . $e->getMessage() ."<p>"; } $sth = $atributestable->prepare("SELECT member_keys, required FROM AtributesT;"); $sth->execute(); $sth->bindColumn('member_keys', $memkey); $sth->bindColumn('required', $reqval); $req = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $required[$memkey] = $reqval; } $sth = $atributestable->prepare("SELECT member_keys, errmessage FROM AtributesT;"); $sth->execute(); $sth->bindColumn('member_keys', $memkey); $sth->bindColumn('errmessage', $errval); $req = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $errmessage[$memkey] = $errval; } $sth = $atributestable->prepare("SELECT member_keys, regxfilter FROM AtributesT;"); $sth->execute(); $sth->bindColumn('member_keys', $memkey); $sth->bindColumn('regxfilter', $regxval); $req = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $regxfilter[$memkey] = $regxval; } $sth = $atributestable->prepare("SELECT member_keys, submitform FROM AtributesT;"); $sth->execute(); $sth->bindColumn('member_keys', $memkey); $sth->bindColumn('formsubmit', $fsv); $formsubmit = array(); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $formsubit[$memkey] = $fsv; } $some = array(); $hasError = self::BiancaData($member, $some); $member_keys = array_keys($member); foreach ($member_keys as $k) { if (empty($_POST[$k])) { if (!empty($required[$k])) { if ($required[$k] <> 'false' || $required[$k] == 'not required' || $required[$k] == NULL) { $hasErr[$k] = 'REQUIRED FEILD'; }} else { $hasErr[$k] = NULL; $member[$k][0] ='';} } else { switch($k) { case $k === ('username' || 'firstname' || 'lastname'): if (!preg_match("/^[a-zA-Z ]*$/",$_POST[$k])) { $hasErr[$k] = "may only contain letters, numbers, spaces and hyphen"; $_POST[$k] = ""; $member[$k] = ""; } else { $member[$k][0] = $_POST[$k];} break; case $k === 'email': if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$_POST[$k])) { $hasErr[$k] = "not a vaild e-mail address"; $_POST[$k] = ""; $member[$k] = ""; } else { $member[$k][0] = $_POST[$k];} break; default: if (!preg_match("/^[a-zA-Z ]*$/",$_POST[$k])) { $hasErr[$k] = "may only contain letters, numbers, spaces and hyphen"; $_POST[$k] = ""; $member[$k] = ""; } else { $member[$k][0] = $_POST[$k];} break; } if (!empty($regxfilter[$k])) { if (!preg_match("$regxfilter",$_POST[$k])) { $hasErr[$k] = "may only contain letters, numbers, spaces and hyphen"; $_POST[$k] = ""; $member[$k] = ""; } else { $member[$k][0] = $_POST[$k];} } } } return $member; } function MemberRegister () { try { $atributestable = new PDO('mysql:host=localhost;dbname=MemberDB', 'root', 'PASSWORD HERE'); } catch (Exception $e) { echo "Unable to connect: " . $e->getMessage() ."<p>"; } $sth = $atributestable->prepare("SELECT username, email FROM MemberT;"); $sth->execute(); $sth->bindColumn('username', $users); $sth->bindColumn('email', $em); $sth->bindColumn('password', $pass); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $username[$users] = $password; $email[$em] = $password; } if ($_SESSION['field']['username']) { $registerme = FALSE; $_SESSION['hasErr']['username'] = 'SORRY, USER NAME IS TAKEN'; } else { $registerme = TRUE; } if ($_SESSION['field']['email']) { $registerme = FALSE; $_SESSION['hasErr']['email'] = 'SORRY, THIS EMAIL IS ALREADY REGISTERED -- get your password!'; } return $registerme; } function MemberLogin () { try { $atributestable = new PDO('mysql:host=localhost;dbname=MemberDB', 'root', 'PASSWORD HERE'); } catch (Exception $e) { echo "Unable to connect: " . $e->getMessage() ."<p>"; } $sth = $atributestable->prepare("SELECT username, email FROM MemberT;"); $sth->execute(); $sth->bindColumn('username', $users); $sth->bindColumn('email', $em); $sth->bindColumn('password', $pass); while ($row = $sth->fetch(PDO::FETCH_BOUND)) { $username[$users] = $password; $email[$em] = $password; } if ($_POST['$username']) { $logmein = password_verify($_POST['pass'], $username[$_POST[$username]]); } if ($_POST['$email']) { $logmein = password_verify($_POST['pass'], $username[$_POST[$username]]); } return $logmein; } function BiancaData ($mymember, $yourmember) { $themember = NULL; $mymember_keys = array_keys($mymember); $yourmember_values = array_values($yourmember); foreach ($mymember_keys as $i) { $themember = array ('$i' => '$yourmember_values[$i]'); } return $themember; } function BiancaDataDefault ($mymember, $yourmember) { $themember = NULL; $mymember_keys = array_keys($mymember); $yourmember_values = array_values($yourmember); for ($i = 0; $i <= count($mymember) - 1; $i++) { $themember[$mymember_keys[$i]] = $yourmember_values[$mymember_keys[$i]]; if (!$themember[$mymember_keys[$i]]) {$themember[$mymember_keys[$i]] = $mymember[$mymember_keys[$i]];} return $themember; } } function MemberRouter ($routeme) { switch ($routeme) { case 'routeback': $Routed = '$_SERVER["PHP_SELF"]'; break; case 'login': $Routed = './loggedin.php'; break; case 'loggedin': $Routed = './loggedin.php'; break; case 'register': $Routed = './register.php'; break; } return $Routed; } function MemberFormType ($FormTYPE) { switch ($FormTYPE) { case login: $noob = new NoobMember; if ($noob->PostData()) { MemberRoute('routeback', $Routed); } else { MemberRoute('login', $Routed); if ($noob->MemberVerify()) { $noob->MemberLogin(); } else { echo 'denied service!!!'; } } brake; case register: $noob = new NoobMember; if ($noob->PostData()) { $formaction = 'echo htmlspecialchars($_SERVER["PHP_SELF"])'; echo "FUCK"; } else { echo "CONGRADULATIONS"; } brake; case forgotpassword: brake; case edit5: brake; } } function MemberHTMLone () { $FLine[0] = array('Your e-mail Address', 'text', 'email'); $FLine[1] = array('Choose Your Login Name', 'text', 'login'); $FLine[2] = array('Your Site Password', 'text', 'password'); echo ' <table>'; echo ' <p><span class="error">* required field.</span></p>'; for ($m = 0; $m <= count($FLine) - 1; $m++) { echo '<tr><th>' , $FLine[$m][0] , '</th><th><input type="' , $FLine[$m][1] , '" name="' , $FLine[$m][2] , '" value="' , $member[$FLine[$m][2]] , '"></th><th><span class="error">' , $hasError[$FLine[$m][2]] , '</span><br></th></tr>'; } } }///////CLASS END $noob = new NoobMember; $noob->PostData(); ?> <html> <body> <?php $email = $username = $password = $firstname = $lastname = $homephone = $address = $address2 = $city = $state = $zip = $cellphone = $submit = $Routed = NULL; session_start(); require "NoobMember.php"; ?> <h2>Website Registration</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <table> <tr><th>Your e-mail Address</th> <th> <input type="text" name="email" value="<?php echo $_SESSION['field']['email'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['email'];?></span><br></th> </tr> <tr><th>Choose Your Login Name</th> <th> <input type="text" name="username" value="<?php echo $_SESSION['field']['username'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['username'];?></span> <br></th> </tr> <tr><th>Your Site Password</th> <th><input type="text" name="password" value="<?php echo $_SESSION['field']['password'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['password'];?></span><br></th> </tr> <tr><th>First Name</th> <th> <input type="text" name="firstname" value="<?php echo $_SESSION['field']['firstname'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['firstname'];?></span> <br></th> </tr> <tr><th>Last Name</th> <th> <input type="text" name="lastname" value="<?php echo $_SESSION['field']['lastname'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['lastname'];?></span> <br></th> </tr> <tr><th>Home Telephone Number</th> <th> <input type="text" name="homephone" value="<?php echo $_SESSION['field']['homephone'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['homephone'];?></span> <br></th> </tr> <tr><th>Address line 1</th> <th> <input type="text" name="address" value="<?php echo $_SESSION['field']['address'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['address'];?></span> <br></th> </tr> <tr><th>Address line 2</th> <th> <input type="text" name="address2" value="<?php echo $_SESSION['field']['address2'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['address2'];?></span> <br></th> </tr> <tr><th>City</th> <th> <input type="text" name="city" value="<?php echo $_SESSION['field']['city'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['city'];?></span> <br></th> </tr> <tr><th>State</th> <th> <input type="text" name="state" value="<?php echo $_SESSION['field']['state'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['state'];?></span> <br></th> </tr> <tr><th>Zip Code</th> <th> <input type="text" name="zip" value="<?php echo $_SESSION['field']['zip'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['zip'];?></span> <br></th> </tr> <tr><th>Cellphone Number</th> <th> <input type="text" name="cellphone" value="<?php echo $_SESSION['field']['cellphone'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['cellphone'];?></span> <br></th> </tr> <tr><th><input type="submit" name="submit" value="register"></th></tr> </table> </form> </body> </html> <?php $noob = new NoobMember; $noob->PostData(); if ($Routed == 'register') { if ($noob->MemberRegister()) { echo "********************HAS REGISTERED********************"; } else { MemberRouter(routeback); } } ?> <html> <body> <?php $email = $username = $password = $firstname = $lastname = $homephone = $address = $address2 = $city = $state = $zip = $cellphone = $submit = $Routed = NULL; session_start(); require "NoobMember.php"; ?> <h2>Website Registration</h2> <p><span class="error">* required field.</span></p> <form method="post" action="#"> <table> <tr><th>Your e-mail Address</th> <th> <input type="text" name="email" value="<?php echo $_SESSION['field']['email'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['email'];?></span><br></th> </tr> <tr><th>Choose Your Login Name</th> <th> <input type="text" name="username" value="<?php echo $_SESSION['field']['username'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['username'];?></span> <br></th> </tr> <tr><th>Your Site Password</th> <th><input type="text" name="password" value="<?php echo $_SESSION['field']['password'];?>"></th> <th><span class="error">* <?php echo $_SESSION['hasErr']['password'];?></span><br></th> </tr> <tr><th><input type="submit" name="submit" value="login"></th></tr> </table> </form> </body> </html> <?php $noob = new NoobMember; $noob->PostData(); if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($Routed == 'login') { if ($noob->MemberLogin()) { echo "********************HAS LOGGED IN********************"; //$out = "home.php"; htmlspecialchars("home.php"); } else { MemberRouter(routeback); htmlspecialchars($_SERVER["PHP_SELF"]); } } } ?> Five hours of cleaning and it would be less than 30 lines I imagine. What has been bothering me lately are the undeclared variable errors. I don't mind declaring but I fear that I'll come back in on segway and have my data NULL'd. Not a difficult proposition, but it's not a pretty proposition either. I really hate it when it gets in my text boxes. Edited February 21, 2014 by Augury Quote Link to comment Share on other sites More sharing options...
Solution Augury Posted February 21, 2014 Author Solution Share Posted February 21, 2014 I remembered to remove the password this time as well. hehehe 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.