tribol Posted April 6, 2010 Share Posted April 6, 2010 Hey all, quick question here. I've created a form and people seem to think that they can submit they're nickname with spaces in it. I've posted the snippet of code below and my edit for the ctype_space is on line 3. My question is will it parse knowing that I'm talking about the nickname since the last line was $check_nickname? or am i missing something... btw $check_nickname is a function passed to mysql and in this case the trim() function won't work since it only checks for spaces in the prefix and suffix. [win] means the nickname has been checked against the database and is good to go. Help? (sorry if i worded it confusingly) if ($check_email) $errors.="- Someone has already registered using that email address<br />"; if ($_POST['win']=="yes" && $check_nickname) $errors.="- Someone has already taken that nickname. Please choose another<br />"; if ($_POST['win']=="yes" && $ctype_space) $errors.="- You cannot use spaces in your nickname. Please try again.<br />"; //to use for checking spaces in nickname if (!$_POST['firstName']) $errors.="- Your first name is required<br />"; if (!$_POST['lastName']) $errors.="- Your last name is required<br />"; if ($_POST['win']=="yes" && !$_POST['nickname']) $errors.="- Your nickname is required<br />"; if (!$_POST['email']) $errors.="- Your email is required<br />"; if (!$_POST['password']) $errors.="- Please senter a password<br />"; if (!$_POST['retype']) $errors.="- Please retype your password<br />"; if ($_POST['password'] && $_POST['retype'] && $_POST['password']!=$_POST['retype']) $errors.="- The passwords you typed do not match<br />"; thx tribol Quote Link to comment Share on other sites More sharing options...
nafetski Posted April 6, 2010 Share Posted April 6, 2010 Yep, the way your logic is nested each of those true statements should go into the errors variable. Quote Link to comment Share on other sites More sharing options...
tribol Posted April 6, 2010 Author Share Posted April 6, 2010 I understand what you're saying but i'm just maintaining this site, it was built by someone else. I'm getting closer, boiled it down to: if (!$ctype_space['nickname']) $errors.="- You cannot use spaces in your nickname. Please try again.<br />"; Except when i do it this way it brings up the error no matter what, if I remove the ! at the beginning of the statement it doesn't work at all. Quote Link to comment Share on other sites More sharing options...
tribol Posted April 9, 2010 Author Share Posted April 9, 2010 Ok, will someone please explain to me why this isn't working??? if (ctype_space($_POST['nickname'])==true) $errors.="- You cannot use spaces in your nickname. Please try again.<br />"; //to use for checking spaces in nickname I've got everything right so far as I can tell, i've gone over it again and again... but for some reason it's not doing anything! grrr.. Quote Link to comment Share on other sites More sharing options...
ddubs Posted April 9, 2010 Share Posted April 9, 2010 I see you sorted this out on IRC - but incase someone else lands here wondering the same thing - ctype_space will ONLY return true if the ENTIRE string is whitespace characters. Quote Link to comment Share on other sites More sharing options...
tribol Posted April 9, 2010 Author Share Posted April 9, 2010 I don't believe I didn't pick that up from all the reading i've been doing about it for the last couple days but yeah that's right. I figured it out using strstr($_POST['nickname']," ")==true to check if there were any spaces and returned an error message if there were. thx 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.