регистер система брой букви в usernam

chaser

Registered
Имам една регистер система въпросът мие как да направя , че като се пише в полето username за регистрация да не може да се регистрираш ако username е помалко от 6 символа и ли букви ето и формата
Код:
<?php 
ob_start(); 
// allows you to use cookies 
include("conf.php"); 
//gets the config page 
if ($_POST[register]) { 
// the above line checks to see if the html form has been submitted 
$username = $_POST[username]; 
$password = $_POST[pass]; 
$cpassword = $_POST[cpass]; 
$email = $_POST[emai1]; 
//the above lines set variables with the user submitted information 
if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) { 
//checks to make sure no fields were left blank 
echo "A field was left blank."; 
}else{ 
//none were left blank! We continue... 
if($password != $cpassword) { 
// the passwords are not the same! 
echo "Passwords do not match"; 
}else{ 
// the passwords are the same! we continue... 
$password = md5($password); 
// encrypts the password 
$checkname = mysql_query("SELECT username FROM users WHERE username='$username'"); 
$checkname= mysql_num_rows($checkname); 
$checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); 
$checkemail = mysql_num_rows($checkemail); 
if ($checkemail>0|$checkname>0) { 
// oops...someone has already registered with that username or email! 
echo "The username or email is already in use"; 
}else{ 
// noone is using that email or username! We continue... 
$username = htmlspecialchars($username); 
$password = htmlspecialchars($password); 
$email = htmlspecialchars($email); 
// the above lines make it so that there is no html in the user submitted information. 
//Everything seems good, lets insert. 
$query = mysql_query("INSERT INTO users (username, password, email,avatar) VALUES('$username','$password','$email','$avatar')"); 
// inserts the information into the database. 
echo "Акаунта е създаден успешно!"; 
} 
} 
} 
} 
else 
{ 
// the form has not been submitted...so now we display it. 
echo (" 
 

<div class='login'>
<form  method='POST'>
<table class='lista' style='width:440px;' align='center' cellspacing='2' cellpadding='5'>
<tr>
<td class='header' align='center' colspan='2'>Създай нов акаунт</td>
</tr>
<tr>
<td class='lista' align='right' width='40%'>Потребителско име:</td>
<td class='lista'><input type=\"text\"  maxlength=\"25\" name=\"username\"  id=\"txt1\" onkeyup=\"showHint(this.value)\"/><br /> </td>
<p><span id='txtHint'></span></p>
</tr>
<tr>
<td class='lista' align='right'>Парола:</td>
<td class='lista'><input type='password' name='pass'></td>
</tr>
<tr>
<td class='lista' align='right'>Повтори паролата:</td>
<td class='lista'><input type='password' name='cpass'></td>
</tr>
<tr>
<td class='lista' align='right'>Email адрес:</td>
<td class='lista'><input type='text' name='emai1'></td>
</tr>
<tr>
<td class='lista' align='right'> </td>
<td class='lista'><input type='submit' name='register' value='Регистрирай ме!'></td>
</tr>
</table>
</form>
</div>
"); 
} 
?>
<meta http-equiv="ContentType" content="text/html; charset=windows-1251" />
<script language="javascript">
var xmlhttp

function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="gethint.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
</script>
<link rel='stylesheet' type='text/css' href='style/web.css'/>
<link rel='stylesheet' type='text/css' href='style/login.css'/>
 
Код:
<?php
ob_start();
// allows you to use cookies
include("conf.php");
//gets the config page
if ($_POST[register]) {
// the above line checks to see if the html form has been submitted
$username = $_POST[username];
$password = $_POST[pass];
$cpassword = $_POST[cpass];
$email = $_POST[emai1];

$duljina =  strlen($username);

//the above lines set variables with the user submitted information
if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) {
//checks to make sure no fields were left blank
echo "A field was left blank.";
}else{
//none were left blank! We continue...
if($password != $cpassword) {
// the passwords are not the same!
echo "Passwords do not match";
}
else if ($duljina < 6) {

echo "Въведете по-дълго username";

}else{
// the passwords are the same! we continue...
$password = md5($password);
// encrypts the password
$checkname = mysql_query("SELECT username FROM users WHERE username='$username'");
$checkname= mysql_num_rows($checkname);
$checkemail = mysql_query("SELECT email FROM users WHERE email='$email'");
$checkemail = mysql_num_rows($checkemail);
if ($checkemail>0|$checkname>0) {
// oops...someone has already registered with that username or email!
echo "The username or email is already in use";
}else{
// noone is using that email or username! We continue...
$username = htmlspecialchars($username);
$password = htmlspecialchars($password);
$email = htmlspecialchars($email);
// the above lines make it so that there is no html in the user submitted information.
//Everything seems good, lets insert.
$query = mysql_query("INSERT INTO users (username, password, email,avatar) VALUES('$username','$password','$email','$avatar')");
// inserts the information into the database.
echo "Акаунта е създаден успешно!";
}
}
}
}
else
{
// the form has not been submitted...so now we display it.
echo ("
 

<div class='login'>
<form  method='POST'>
<table class='lista' style='width:440px;' align='center' cellspacing='2' cellpadding='5'>
<tr>
<td class='header' align='center' colspan='2'>Създай нов акаунт</td>
</tr>
<tr>
<td class='lista' align='right' width='40%'>Потребителско име:</td>
<td class='lista'><input type=\"text\"  maxlength=\"25\" name=\"username\"  id=\"txt1\" onkeyup=\"showHint(this.value)\"/><br /> </td>
<p><span id='txtHint'></span></p>
</tr>
<tr>
<td class='lista' align='right'>Парола:</td>
<td class='lista'><input type='password' name='pass'></td>
</tr>
<tr>
<td class='lista' align='right'>Повтори паролата:</td>
<td class='lista'><input type='password' name='cpass'></td>
</tr>
<tr>
<td class='lista' align='right'>Email адрес:</td>
<td class='lista'><input type='text' name='emai1'></td>
</tr>
<tr>
<td class='lista' align='right'> </td>
<td class='lista'><input type='submit' name='register' value='Регистрирай ме!'></td>
</tr>
</table>
</form>
</div>
");
}
?>
<meta http-equiv="ContentType" content="text/html; charset=windows-1251" />
<script language="javascript">
var xmlhttp

function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="gethint.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
</script>
<link rel='stylesheet' type='text/css' href='style/web.css'/>
<link rel='stylesheet' type='text/css' href='style/login.css'/>
 

Back
Горе