kittrellbj Posted January 23, 2010 Share Posted January 23, 2010 Hi, everyone, I just can't see to track down my error here. The problem is that $register->validate() keeps returning false, and I can't find any problems with it anywhere. I've been staring at it all day, so maybe a fresh pair of eyes will be able to spot something. So, here's the way the script works. Users enter their information on the registration form, the form $_POSTs, and the data is validated by the validate function. It is *suppose* to return true if the information is validated. Here is the validate() function: function validate() { if ( (ctype_alnum($_POST[$username]) && !strlen($_POST[$username]) <= 4 && !strlen($_POST[$username] >= 13)) && (ctype_alpha($_POST[$userchar]) && !strlen($_POST[$userchar]) <= 2 && !strlen($_POST[$userchar]) >= 13) && (filter_var($_POST[$useremail], FILTER_VALIDATE_EMAIL)) && (ctype_alnum($_POST[$userpass]) && !strlen($_POST[$userpass]) <= 4 && !strlen($_POST[$userpass] >= 33)) && (ctype_alnum($_POST[$userpass2]) && !strlen($_POST[$userpass2]) <= 4 && !strlen($_POST[$userpass2] >= 33)) && ($_POST[$userpass] == $_POST[$userpass2]) && ($_POST[$termsofservice] == 1) && ($_POST['send'])) { return true; } else { return false; } I did a print_r($_POST) to make sure the $variables I was using instead of "keys" on $_POST was working. (I use $_POST[$key] instead of $_POST["key"], and the array returns correctly.) This is the form that users sign up to: <form method="post" id="customForm" action=""> <label for="user">Username</label> <input id="username" name="username" type="text" /> <span id="usernameInfo">Enter your username (for logging in).</span> <label for="name">Character Name</label> <input id="charname" name="charname" type="text" /> <span id="nameInfo">Enter your character's first name.</span> <label for="useremail">Valid E-mail Address</label> <input id="useremail" name="useremail" type="text" /> <span id="emailInfo">Valid E-mail please, you will need it to log in!</span> <label for="userpass">Password</label> <input id="userpass" name="userpass" type="password" /> <span id="userpass1Info">At least 5 characters: letters and/or numbers</span> <label for="userpass2">Re-type password to confirm.</label> <input id="userpass2" name="userpass2" type="password" /> <span id="pass2Info">Re-type password to confirm.</span><br /><br /> </center><label for="message">Do you Agree to the Terms of Service? (View the Terms of Service here)</label> <input type="checkbox" id="termsofservice" name="termsofservice" value="1" /> <strong>I accept the terms of service!</strong><br /> <br /> <center><input id="send" name="send" type="submit" value="Register" /></center> Any help is appreciated greatly. Link to comment https://forums.phpfreaks.com/topic/189519-register-validate-returning-eternal-bool-false/ Share on other sites More sharing options...
sasa Posted January 23, 2010 Share Posted January 23, 2010 in your function local variables ($username, ...) isn't declare Link to comment https://forums.phpfreaks.com/topic/189519-register-validate-returning-eternal-bool-false/#findComment-1000347 Share on other sites More sharing options...
oni-kun Posted January 23, 2010 Share Posted January 23, 2010 Your code is riddled with errors, look at these lines for example: !strlen($_POST[$username] >= 13)) !strlen($_POST[$userchar]) >= 13) You're forgetting to close brackets for one. $_POST[$username] <-- As mentioned $username has to be passed the the function. $username is NULL if it is not passed or defined wtihin. function validate($username, $userchar, $userpass, $userpass2, $termsofservice) { ... Link to comment https://forums.phpfreaks.com/topic/189519-register-validate-returning-eternal-bool-false/#findComment-1000348 Share on other sites More sharing options...
kittrellbj Posted January 23, 2010 Author Share Posted January 23, 2010 Thanks a bunch. It's amazing what a good night's sleep will do for you, combined with a fresh set of eyes to point out mistakes. Here's the fixed code, finally returning true: (from function validate() ) function validate() { global $username, $userchar, $useremail, $userpass, $userpass2, $termsofservice; if ( (ctype_alnum($_POST[$username]) && strlen($_POST[$username]) >= 5 && strlen($_POST[$username]) <= 12) && (ctype_alpha($_POST[$userchar]) && strlen($_POST[$userchar]) >= 3 && strlen($_POST[$userchar]) <= 12) && (filter_var($_POST[$useremail], FILTER_VALIDATE_EMAIL)) && (ctype_alnum($_POST[$userpass]) && strlen($_POST[$userpass]) >= 5 && strlen($_POST[$userpass]) <= 32) && (ctype_alnum($_POST[$userpass2]) && strlen($_POST[$userpass2]) >= 5 && strlen($_POST[$userpass2]) <= 32) && ($_POST[$userpass] == $_POST[$userpass2]) && ($_POST[$termsofservice] == 1) ) { return true; } else { return false; } Can't believe I forgot about global. Sheesh. And I attribute the strange ( )'s to being extremely tired by getting to this part of the code. Thanks for all the help. <3 phpfreaks Link to comment https://forums.phpfreaks.com/topic/189519-register-validate-returning-eternal-bool-false/#findComment-1000476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.