MrCostari Posted December 20, 2011 Share Posted December 20, 2011 I'm making a website for school and I want the registered username contain no more than 14 charactars and no less than 5. For the password is < 16 and < 6 But it seems to always given that error, and skipping the check of a in use username and email. Can anybody help me with this please? I have been searching a bit for the strlen with username < 14 help but everywhere it seems to be the same code a I use. So it might be something totally different. Here is my code: (sorry for the Dutch) <?php error_reporting(0); $link = mysql_connect('localhost', 'root', ''); $db_selected = mysql_select_db('website', $link); include ("includes/class.TemplatePower.inc.php"); $tpl = new TemplatePower("registratie.html"); $tpl->prepare(); switch($_GET['actie']) { case regis_sql: if(isset($_POST['submit'])) { if(strlen($gebruikersnaam) > 14 || strlen($gebruikersnaam) < 5) // controleren of de gebruikersnaam niet meer dan 14 tekens en niet minder dan 5 tekens bevat { $tpl->newBlock("TUSSEN_TEKENS1"); $tpl->assign("TUSSEN_TEKENS1", "Uw gebruikersnaam mag niet meer dan 14 tekens en niet minder dan 5 tekens bevatten."); } else // als de gebruikersnaam goed ingevuld is doorgaan met controleren { $res1 = mysql_query("SELECT * FROM accounts WHERE gebruikersnaam = '".$gebruikersnaam."'"); $num1 = mysql_num_rows($res1); //controleren of de gebruikersnaam al bestaat in de database if($num1 == 1) { $tpl->newBlock("GEBR_BEZET"); $tpl->assign("GEBR_BEZET", "De door u ingevulde gebruikersnaam is al bezet."); } else // als de gebruikersnaam nog niet bestond doorgaan met controleren { if(strlen($wachtwoord) > 16 || strlen($wachtwoord) < 6) // controleren of het wachtwoord niet meer dan 16 tekens en niet minder dan 6 tekens bevat { $tpl->newBlock("TUSSEN_TEKENS2"); $tpl->assign("TUSSEN_TEKENS2", "Uw wachtwoord mag niet meer dan 16 tekens en niet minder dan 6 tekens bevatten."); } else // als het email adres goed ingevuld is doorgaan met controleren { $res2 = mysql_query("SELECT * FROM personen WHERE email = '".$email."'"); $num2 = mysql_num_rows($res2); // controleren of het email adres al bestaat in de database if($num2 == 1) { $tpl->newBlock("MAIL_BEZET"); $tpl->assign("MAIL_BEZET", "Het door u ingevulde email adres is al bezet."); } else // als het email adres nog niet bestond doorgaan met controleren { $res1 = mysql_query("INSERT INTO accounts (gebruikersnaam, wachtwoord, groepenid) VALUES ('".$_POST['gebruikersnaam']."', '".sha1($_POST['wachtwoord'])."', 1)"); $accountsid = mysql_insert_id(); $res2 = mysql_query("INSERT INTO personen (voornaam, achternaam, adres, postcode, plaats, email, telnr, accountsid) VALUES ('".$_POST['voornaam']."', '".$_POST['achternaam']."', '".$_POST['adres']."', '".$_POST['postcode']."', '".$_POST['plaats']."', '".$_POST['email']."', '".$_POST['telnr']."', '".$accountsid."')"); $tpl->newBlock("REGIS_DONE"); $tpl->assign("REGIS_DONE", "Bedankt voor het registreren! U kunt nu inloggen met uw account."); } } } } } break; default: $tpl->newBlock("REGIS_FORM"); } $tpl->printToScreen(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/253546-no-more-than-14-and-no-less-than-5-charactars-is-always-given/ Share on other sites More sharing options...
SergeiSS Posted December 20, 2011 Share Posted December 20, 2011 Dutch is not a problem But about your logic..... First, you check if there is one variable from GET array. Second, you check if there is one more variable, but now from POST array. Are you sure that you have both GET & POST in the same time? It possible, of course, but it's not good idea. print this code BEFORE switch() echo '<pre>'.print_r($_GET,1).'</pre><pre>'.print_r($_POST).'</pre>'; and show us the result Quote Link to comment https://forums.phpfreaks.com/topic/253546-no-more-than-14-and-no-less-than-5-charactars-is-always-given/#findComment-1299724 Share on other sites More sharing options...
Drongo_III Posted December 20, 2011 Share Posted December 20, 2011 You are calling strlen on the string $gebruikersnaam . But where is that getting set? Quote Link to comment https://forums.phpfreaks.com/topic/253546-no-more-than-14-and-no-less-than-5-charactars-is-always-given/#findComment-1299729 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 Why are you overriding error_reporting and setting it to 0 while trying to debug? Set error_reporting to -1 and display_errors to On. error_reporting(-1); ini_set('display_errors', 'On'); Quote Link to comment https://forums.phpfreaks.com/topic/253546-no-more-than-14-and-no-less-than-5-charactars-is-always-given/#findComment-1299796 Share on other sites More sharing options...
Drummin Posted December 20, 2011 Share Posted December 20, 2011 EDIT: SergeiSS' pointed out the real issue with a post inside a get. The code/form directing to this page might help. Quote Link to comment https://forums.phpfreaks.com/topic/253546-no-more-than-14-and-no-less-than-5-charactars-is-always-given/#findComment-1299835 Share on other sites More sharing options...
MrCostari Posted December 23, 2011 Author Share Posted December 23, 2011 Sorry for the late response, I solved it! Had to set a variable for email which I did for username to haha Thanks anyway! Quote Link to comment https://forums.phpfreaks.com/topic/253546-no-more-than-14-and-no-less-than-5-charactars-is-always-given/#findComment-1300798 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.