Jump to content

No more than 14 and no less than 5 charactars is always given


MrCostari

Recommended Posts

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();
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.