Mythic Fr0st Posted December 2, 2006 Share Posted December 2, 2006 I get a parse errrorParse error: parse error in c:\program files\easyphp1-8\www\test\signup.php on line 57im trying to get the string length of the text boxes, username, password, password confirm, and same for email,I want it to stop if they dont match, I think im using strlen wrong though...[code]<input type='submit' value='Signup' onsubmit='DM()'>[/code][code]<?phpfunction DM(){$i=(!strlen('user'))$pw[1]=(!strlen('pw1'))$pw[2]=(!strlen('pw2'))$em[1]=(!strlen('email1')$em[2]=(!strlen('email2')}?>[/code]im trying to set (!strlen('NameOfTXTbox')) to a variable called $i, but I get error :/, neeed this fixed badly, Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/ Share on other sites More sharing options...
kickassamd Posted December 2, 2006 Share Posted December 2, 2006 [code]<?function checkLength($test, $minLength){ if (strlen($test) < $minLength) { return false; } else { return true; }}// Use it like thisif (!checkLength($_POST['user'], 4)){ echo "Username Not Long Enough!";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133792 Share on other sites More sharing options...
kickassamd Posted December 2, 2006 Share Posted December 2, 2006 [code]<input type='submit' value='Signup' onsubmit='DM()'>[/code]Will never work even if you have he right code... PHP is a server side language and can not be used on the client side Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133798 Share on other sites More sharing options...
corbin Posted December 2, 2006 Share Posted December 2, 2006 Also, never rely on JS alone for input checking as javascript can be disabled. Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133799 Share on other sites More sharing options...
kickassamd Posted December 2, 2006 Share Posted December 2, 2006 Correct always use Server Side to handle registrations because anything client can always have a work around. Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133800 Share on other sites More sharing options...
Mythic Fr0st Posted December 2, 2006 Author Share Posted December 2, 2006 Okay, your code works, but I need it to stop the browser immediately from continuing[code]function checkLength($user, $minLength){ if (strlen($user) < $minLength) { return false; } else { return true; }}if (!checkLength($_POST['user'], 4)){ echo 'Your username requires atleast 5 characters';}?>[/code]what code do I use for that? Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133812 Share on other sites More sharing options...
kickassamd Posted December 2, 2006 Share Posted December 2, 2006 add exit(); after the echo statement and it will stop the browserOr you can have the browser redirect back to the login page with an error displayed. Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133816 Share on other sites More sharing options...
Mythic Fr0st Posted December 2, 2006 Author Share Posted December 2, 2006 SO exit() will just basically, pause the browser and leave it on the same page?and redirect thing, will take it back to the same page, with a new error... hmm, Redirect sounds good!and, whenever I click refresh, if username & password boxes, arent atleast 5 chars, or passwords & e-mails dont match, it displays it, anyway to make it redirect back to the browser, and display them then? Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133823 Share on other sites More sharing options...
kickassamd Posted December 2, 2006 Share Posted December 2, 2006 redirect code: replace the echo with this...[code]header("location: http://something.com/signuppage.php?error=tooshort");[/code]on signuppage.php[code]if ($_POST['error'] == tooshort){ echo "The username you entered was too short";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133828 Share on other sites More sharing options...
kickassamd Posted December 2, 2006 Share Posted December 2, 2006 Message me its easier to diagnose etc etc over IM insted of here. Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133831 Share on other sites More sharing options...
trq Posted December 2, 2006 Share Posted December 2, 2006 [quote]Message me its easier to diagnose etc etc over IM insted of here.[/quote]I think your missing the point of the board. Quote Link to comment https://forums.phpfreaks.com/topic/29183-trying-to-use-strlen-to-get-length-of-username-pw-email-error/#findComment-133835 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.