Voilà, j'ai bidulé un script php et fais appel à des fonctions MySQL pour régler mon problème. Je suis arrivé presque mais je suis bloqué et j'ai besoin de votre aide pour finaliser ma page svp :
Voici ma table :
CREATE TABLE IF NOT EXISTS 'Key_Computrace' (
'id' int(10) NOT NULL AUTO_INCREMENT,
'ExistKey' varchar(29) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
'VerifKey' varchar(29) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
INSERT INTO 'Key_Computrace' ('id', 'ExistKey', 'VerifKey') VALUES
(1,'3UNLD-3GSYQ-XDWAW-EUWZS-NZN2E','3UNLD-3GSYQ-XDWAW-EUWZS-NZN2E'),
(2,'TWDHG-7BG7J-OFM60-HPJ8L-D2EYI','TWDHG-7BG7J-OFM60-HPJ8L-D2EYI'),
(3,'PA0B8-I5PMC-JT90S-0B9PO-01VGP','0');
Voici ma page en intégrale :
<?php
if (isset($_POST["Valid"])) {
$Valid = $_POST["Valid"];
mysql_connect("127.0.0.1", "root", "");
mysql_select_db("computracekey");
/* 1- ExistKey = VerifKey */
$req=mysql_query("select * from key_computrace where ExistKey='$Valid' and VerifKey='$Valid'");
$nb= mysql_num_rows($req);
if ( $nb > 0 )
header ('Valide.php'); //Ouvre la page si conditions OK
/* 2- If Key not ExistKey then Refresh */
$req=mysql_query("select * from key_computrace where ExistKey<>'$Valid'");
$nb= mysql_num_rows($req);
if ( $nb > 0 )
header ('KeyProduct.php'); //Reouvre la page en cours
/* 3- If Key = ExistKey and VerifKey = 0 then Redirect to Verif.php */
$req=mysql_query("select * from key_computrace where ExistKey<>'$Valid' and VerifKey='0'");
$nb= mysql_num_rows($req);
if ( $nb > 0 )
header ('Valide.php');
Puis insert dans la base la clé inscrite dans $Valid dans le ValidKey
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HightSecurity</title>
<style type="text/css">
<!--
body,td,th {font-family: Tahoma;font-size: 13px;}
body {margin: 0px;}
a.Verif {background:url(BoutonVerifier.png) no-repeat; width:89px; height:25px; display:block;}
a.Verif:hover {background-position: bottom center;}
-->
</style>
<script type="text/javascript">
function formatTexte(chaine) {
var p1 = chaine.substring(0,5);
var p2 = chaine.substring(5,10);
var p3 = chaine.substring(10,15);
var p4 = chaine.substring(15,20);
var p5 = chaine.substring(20,25);
document.getElementById('Valid').value = p1 + '-' + p2 + '-' + p3 + '-' + p4 + '-' + p5;
}
</script>
</head>
<body>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="592" align="center" valign="middle" background="Ecran.jpg">
<form id="form1" name="form1" method="post" action="">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" align="center" valign="middle" background="ZoneTexte.png">
<input name="Valid" type="text" id="Valid" maxlength="30" style="border:none; width:98%; font-family:Consolas; font-size:17px;" onKeyUp="javascript:this.value=this.value.toUpperCase();" onChange="javascript:formatTexte(this.value.toUpperCase());" onFocus="this.value=''"/></td>
</tr>
<tr>
<td align="center"> </td>
</tr>
<tr>
<td align="center"><a href="#" class="Verif" onclick="document.getElementById('form1').submit();"></a></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Mon problème se trouves sur 3 points qui sont les conditions MySQL du code :
1- Si la clé existe dans ExistKey et VerifKey alors la page se rafraîchit. (rien ne se passe)
2- Si la clé n'existe pas dans ExistKey, alors la page se rafraîchit. (rien ne se passe)
3- Si la clé entrée existe dans ExistKey et VerifKey = 0 alors il l'ajoute dans VerifKey et il est redirigé vers Valide.php
J'ai essayé de faire de mon mieux mais j'y arrives pas.
Les conditions 1 à 1 passaient mais il y a encore des erreurs.
Pouvez-vous m'aider svp à les corriger ?
