Correction Série 4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Correction série 4

Index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>index</title>
<link rel="stylesheet" href="mesStyles.css">
</head>
<body>
<header>
<h1>Le BONHEURE</h1>
</header>
<NAV>
<ul>
<li><a href="inscription.html" target="zone2">Inscription</a></li>
<li><a href="participation.html"
target="zone2">Participation</a></li>
<li><a href="taux.php" target="zone2">Taux de bonheur</a></li>

</ul>
</NAV>
<section>
<iframe src="inscription.html" frameborder="0" name="zone2"></iframe>
</section>
</body>
</html>
mesStyle.css

header{
background-color: aqua;
}
nav{
background-color: rgb(110, 205, 78);
width: 30%;
height: 480px;
float: left;
}
section{
background-color: rgb(50, 99, 173);
width: 70%;
height: 480px;
float: left;
}
iframe{
width: 99%;
height: 480px;
}
h1{
transition: color 2s;
}
h1:hover{
color: #1b7c9f;
}
.c1{
background-color: rgb(72,201,176);
font-size: 16px;
}
th,label{
color: #C39BD3;
text-decoration: underline #884EA0;
}
Inscription.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inscription</title>
<link rel="stylesheet" href="mesStyles.css">
<script src="controle.js"></script>
</head>
<body>
<h1>Inscription</h1>
<form action="inscription.php" method="POST" onsubmit="return verif1()">
<table>
<tr>
<th>NCIN:</th>
<td><input type="text" id="id1" name="T1" class="c1"></td>
</tr>
<tr>
<th>Nom:</th>
<td><input type="text" id="id2" name="T2" class="c1"></td>
</tr>
<tr>
<th>Prénom:</th>
<td><input type="text" id="id3" name="T3" class="c1"></td>
</tr>
<tr>
<th>Email:</th>
<td><input type="text" id="id4" name="T4" class="c1"></td>
</tr>
<tr>
<th>Etat civil:</th>
<td><input type="radio" id="id5" name="R1" value="C">
<label>Célibataire</label>
<input type="radio" id="id6" name="R1"
value="M"><label>Marié</label>
<input type="radio" id="id7" name="R1"
value="D"><label>Divorcé</label>
</td>
</tr>
<tr>
<td><input type="submit" value="inscription" name="B1"></td>
<td><input type="reset" value="Annuler" name="B2"></td>
</tr>
</table>

</form>
</body>
</html>
Participation.html

<?php
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("bd444sadrag1") or die (mysql_error());
$a=$_POST['T1'];
$b=$_POST['T2'];
$c=$_POST['T3'];
$d=$_POST['T4'];
$e=$_POST['R1'];
$req1="select *
from citoyen
where ncin='$a'";
$r1=mysql_query($req1) or die (mysql_error());
if (mysql_num_rows($r1) != 0){
echo "Vous êtes déjà inscrit parmi les participants";
die();
}
else{
$req2="insert into citoyen
values ('$a','$b','$c','$d','$e')";
$r2=mysql_query($req2) or die (mysql_error());
echo "Merci de s’inscrire";
}
mysql_close();
?>
Controle.js

function verifDate(c){
OK=true;
aaaa=Number(c.substr(0,4));
mm=Number(c.substr(5,2));
jj=Number(c.substr(8,2));
if ((c=="")||(c.length != 10)){
OK=false;
}
if ((aaaa<1000)||(aaaa>9999)){
OK=false;
}
if ((mm<1)||(mm>12)){
OK=false;
}
if ((c.charAt(4) != "-")||(c.charAt(7) !="-")){
OK=false;
}
switch(mm){
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
if ((jj<1)||(jj>31)){
OK=false;
};
break;
case 4:case 6:case 9:case 11:
if ((jj<1)||(jj>30)){
OK=false;
};
break;
case 2:
if (aaaa % 4 == 0){
if ((jj<1) ||(jj>29)){
OK=false;
};
}
else{
if ((jj<1)||(jj>28)){
OK=false;
};
}
break;

return OK;
}
function chiffre(ch){
i=0;
while ((ch.charAt(i)>="0")&&(ch.charAt(i)<="9")&&(i<ch.length)){
i++;//i=i+1
}
return (i==ch.length);

}
function verif1()
{
var a=document.getElementById("id1").value ;
var b=document.getElementById("id2").value ;
var c=document.getElementById("id3").value ;
var d=document.getElementById("id4").value ;

resultat=true;
if ((a=="")||(a.length != 8) ||(chiffre(a) == false)){
alert("Le ncin est invalide");
resultat=false;
}
else{
if ((b=="") || (b.charAt(0)<"A")||(b.charAt(0)>"Z")){
alert("Le nom est invalide");
resultat=false;
}
else{
if ((c=="") || (c.charAt(0)<"A")||(c.charAt(0)>"Z")){
alert("Le prénom est invalide");
resultat=false;
}
else{
if ((d=="")||(d.indexOf("@")==-1)||(d.indexOf(".")==-
1)||(d.indexOf("@")>d.indexOf("."))){
alert("L'email est invalide");
resultat=false;
}
else{
if
((document.getElementById("id5").checked==false)&&(document.getElementById("id
6").checked==false)&&(document.getElementById("id7").checked==false)){
alert("Choisir l'état civil");
resultat=false;
}

}
}

}
return resultat;
}
function check()
{
var a=Document.getElementById("id1").value;
var c=Document.getElementById("id3").value;

resultat=true;
if ((a=="")||(a.length != 8) ||(chiffre(a) == false)){
alert("Le ncin est invalide");
resultat=false;
}
else{
if (document.getElementById("id2").selectedIndex==0){
alert("Choisir votre état");
resultat=false;
}
else{
if (verifDate(c)==false){
alert("Date invalide");
resultat=false;
}
}

}
return resultat;
}
Inscription.php

<?php
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("bd444sadrag1") or die (mysql_error());
$a=$_POST['T1'];
$b=$_POST['T2'];
$c=$_POST['T3'];
$d=$_POST['T4'];
$e=$_POST['R1'];
$req1="select *
from citoyen
where ncin='$a'";
$r1=mysql_query($req1) or die (mysql_error());
if (mysql_num_rows($r1) != 0){
echo "Vous êtes déjà inscrit parmi les participants";
die();
}
else{
$req2="insert into citoyen
values ('$a','$b','$c','$d','$e')";
$r2=mysql_query($req2) or die (mysql_error());
echo "Merci de s’inscrire";
}
mysql_close();
?>
Participer.php

<?php
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("bd444sadrag1") or die (mysql_error());
$a=$_POST['T1'];
$b=$_POST['D1'];
$c=$_POST['T2'];
$req1="select *
from citoyen
where ncin='$a'";
$r1=mysql_query($req1) or die (mysql_error());
if (mysql_num_rows($r1) == 0){
echo "Vous n’êtes pas inscrit parmi les participants";
die();
}
else{
$req2="select *
from participant
where ncin='$a'";
$r2=mysql_query($req2) or die (mysql_error());
if (mysql_num_rows($r2)!=0){
$t=mysql_fetch_row($r2);
echo "Vous avez déjà effectué une participation à la date :".$t[2];
}

else{
$req3="insert into participation
values ('$a','$b','$c')";
$r3=mysql_query($req3) or die (mysql_error());
echo "Merci de participer";

}
}

mysql_close()
?>
Taux.php

<?php
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("bd444sadrag1") or die (mysql_error());
$req1="select count(ncin)
from citoyen";
$r1=mysql_query($req1)or die (mysql_error());
$t1=mysql_fetch_row($r1);
echo "<b>Nombre d’inscrit dans le site : <b>".$t1[0];
echo"<br>";
$req2="select count(*)
from paricipation";
$r2=mysql_query($req2)or die (mysql_error());
$t2=mysql_fetch_row($r2);
echo "<b>Nombre des participant : <b>".$t2[0];
echo"<br>";

$req3="select count(*)
from paricipation
where code='H'";
$r3=mysql_query($req3)or die (mysql_error());
$t3=mysql_fetch_row($r3);
echo "<b>Heureux : <b>".($t3[0]/$t2[0])*100;
echo"<br>";

$req4="select count(*)
from paricipation
where code='M'";
$r4=mysql_query($req4)or die (mysql_error());
$t4=mysql_fetch_row($r4);
echo "<b>Malheureux : <b>".($t4[0]/$t2[0])*100;
echo"<br>";

$req5="select count(*)
from paricipation
where code='T'";
$r5=mysql_query($req5)or die (mysql_error());
$t5=mysql_fetch_row($r5);
echo "<b>Triste : <b>".($t5[0]/$t2[0])*100;
mysql_close();
?>

You might also like