[AJAX] Accés à une page via user et mot de passe avec ajax
Bonjour tout le monde
Je souhaiterais acceder à une page admi avec ajax.
Voici mes codes.
mon formulaire:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<form name="connex" id="connex">
<input type="text" name="nom" id="nom" />
<input type="password" name="mdp" id="mdp"/>
<select name="choiuser" id="choiuser">
<option value="Administrateur"> Administrateur</option>
<option value="utilisateur"> utilisateur</option>
</select>
<input type="button" name="btcon" onClick="acceAdmiuser();" id="btcon" value="accés" />
</form> |
fichier javascript
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
function creationXHR() {
var resultat=null;
try {
resultat= new XMLHttpRequest();
}
catch (Error) {
try {
resultat= new ActiveXObject("Msxml2.XMLHTTP");
}
catch (Error) {
try {
resultat= new ActiveXObject("Microsoft.XMLHTTP");
}
catch (Error) {
resultat= null;
}
}
}
return resultat;
} |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
window.onload=testerNavigateur;
function testerNavigateur() {
objetXHR = creationXHR();
if(objetXHR==null) {
document.getElementById("btcon").disabled= true;
var erreurNavigateur="Erreur Navigateur : Création d'objet XHR impossible";
remplacerContenu("info", erreurNavigateur);
document.getElementById("info").style.visibility="visible";
}
}
function acceAdmiuser(){
if(document.getElementById('nom').value == ""){
document.getElementById('user').style.visibility="visible";
}else if(document.getElementById('mdp').value == ""){
document.getElementById('mp').style.visibility="visible";
}else{
choixAcces();
}
}
function choixAcces(){
if(document.getElementById('choiuser').options[document.getElementById('choiuser').selectedIndex].value == "Administrateur"){
objetXHR = creationXHR();
var parametres ="nom" +"mdp";
objetXHR.open("get","loginadmi.php?"+parametres, true);
objetXHR.send(null);
}
} |
fichier php
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<?php
header("Pragma:no-cache");
$Connexion = mysql_connect("localhost", "root", "");
$connexionbase = mysql_select_db("testbdd");
if(!empty($_POST['nom']) && !empty($_POST['mdp']))
{
$username = $_POST['nom'];
$password = $_POST['mdp'];
$sql = "select passw from log where identifiant='".$username."'";
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$data = mysql_fetch_assoc($req);
if($data['mdp'] != $password) {
echo "<p>Mauvais login / password. Merci de recommencer</p>";
include ("erreurconnex.html");
exit;
}
else {
//session_start();
$_SESSION['nom'] = $username;
include ("supadm.php");
}
}
else {
echo "<p>Vous avez oublié de remplir un champ.</p>";
include ("erreurconnex.html");
exit;
}
?> |
Mon soucis est que rien ne ce passe.
Que manque t'il?
A +