Vérifier si un login est disponible
Bonjour,
je cherhce donc a faire une recherche sur une base de donnée pour vérifier si un login est disponible ou non.
Voici comment je procede :
le code html
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
<div id="conteneur">
<!-- ****************************** etape 1 ****************************** -->
<div id="etape1" class="etape" style="left:0px;">
<form action="" method="post" name="registerForm">
<table width="602" border="0" cellspacing="8" cellpadding="0">
<tr>
<td width="109" height="20" class="inscription">Votre login :</td>
<td width="109" height="20"><input id="loginrules" onkeyup="ins_verification('login','log_valid','log_ok')" type="text" name="login_ins" size="15" maxlength="20" class="input_text" /></td>
<td width="172" height="20" class="ins_valid" id="log_valid" style="display:">4 à 20 caractères, lettres et chiffres sans espace</td>
<td width="172" height="20" class="ins_ok" id="log_ok" style="display:none">Ok</td>
</tr>
<tr>
<td height="20" class="inscription">Votre mot de passe :</td>
<td height="20"><input id="mdprules" onkeyup="ins_verification('mdp','pass_valid','pass_ok')" type="password" name="mdp_ins" size="15" maxlength="40" class="input_text" /></td>
<td height="20" class="ins_valid" id="pass_valid" style="display:">4 à 40 caractères, différent du login</td>
<td height="20" class="ins_ok" id="pass_ok" style="display:none">Ok</td>
</tr>
<tr>
<td height="20" class="inscription">Votre adresse email :</td>
<td height="20"><input type="text" id="mailrules" onkeyup="mail_verification('mail_valid','mail_ok')" name="mail_ins" size="20" class="input_text" maxlength="100" /></td>
<td height="20" class="ins_valid" id="mail_valid" style="display:">Votre email doit être valide</td>
<td height="20" class="ins_ok" id="mail_ok" style="display:none">Ok</td>
</tr>
<tr>
<td height="20" colspan="3" align="center"><input onclick="etape1valider()" type="button" class="boutton" value="Passer à l'étape suivante" /></td>
</tr>
</table>
</form>
</div> |
Seul le premeir input nous interresse .
Voici le code javascript :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
function ins_verification(rules,valid,ok) {
if (rules == 'login') {
var login = document.forms.registerForm.loginrules.value;
} else if(rules == 'mdp') {
var login = document.forms.registerForm.mdprules.value;
}
td = document.getElementById(valid);
tdok = document.getElementById(ok);
if(login.length < 4) {
tdok.style.display = 'none';
td.style.display = '';
td.className = 'ins_warn';
}
else if ((rules == 'mdp') && (login == document.forms.registerForm.loginrules.value)) {
tdok.style.display = 'none';
td.style.display = '';
td.className = 'ins_warn';
}
else if ((rules == 'login') && (file('verif_ins.php?log_base='+escape (login)) == true )) {
alert("marche");
}
else if (login.length > 3) {
td.style.display = 'none';
tdok.style.display = '';
return true;
}
else if (login.length == 0) {
tdok.style.display = 'none';
td.style.display = '';
td.className = 'ins_valid';
}
} |
et enfin le code php qui va chercher ma réponse dans la base de donnée :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
<?php
if (isset($_GET['log_base'])) {
$login = $_GET['log_base'];
$connexion = mysql_connect("127.0.0.1","root","") or die ("probleme de connexion a la base de donnée".mysql_error());
$select_db = mysql_select_db("projet");
$rq = mysql_query("SELECT loginuser FROM `compte` WHERE loginuser = '$login'");
$rq2 = mysql_query("SELECT loginuser FROM `attentevalidation` WHERE loginuser = '$login'");
if (mysql_num_rows($rq) == 0 && mysql_num_rows($rq) == 0) {
return true;
}
else {
return false;
}
}
?> |
le fichier php a l'air de fonctionner,
c'est a ce niveau que ca coince ...
Code:
1 2 3 4 5 6 7 8 9 10
|
else if (
// défini si on vérifie le login ou le mot de passe
(rules == 'login')
&&
// vérifie la disponibilité du login (la que je bloque)
(file('verif_ins.php?log_base='+escape (login)) == true )) {
// si ca marche, je fait une alert.
alert("marche");
} |
merci.
Lien : http://mimagyc.ovh.org/projet/