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 65 66 67 68 69 70 71
| <?php
// On prolonge la session
session_start();
// On teste si la variable de session existe et contient une valeur
if(empty($_SESSION['identifiant']))
{
// Si inexistante ou nulle, on redirige vers le formulaire de login
header('Location: authentification.php');
exit();
}
?>
<p>
<?php
if (preg_match("#^oui$#", $_POST['reponsesondage']))
{
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
// On ajoute un oui dans le nombre de OUI dans la table sondage_pol
$req = $bdd->prepare('UPDATE sondage_pol SET nb_oui = (nb_oui+1) WHERE questpoID = :questpoID');
$req->execute(array('questpoID' => $_POST['questpoID']));
// On ajoute une donnée dans la table historiquereponseidentifiant pour indiquer que le menbre à répodu à la questionID
$req = $bdd->prepare('INSERT INTO historiquereponseidentifiant (questionIDidentifiant,rep_oui) VALUES (?,?)');
$req->execute(array($_POST['questpoID'].$_SESSION['identifiant'],1));
// calcul de statistiques suite à l'incrémentation d'une reponse oUI +1 puis stockage des résultats dans la table sondage_pol
$sql = $bdd->query('SELECT (nb_oui+nb_non) AS c,(nb_oui/(nb_oui+nb_non)*100) AS d, (nb_non/(nb_oui+nb_non)*100) AS e FROM sondage_pol');
while ($donnees = $req->fetch())
{}
$req->closeCursor();
$req = $bdd->prepare('UPDATE sondage_pol SET nb_total_reponse,pourcentage_oui,pourcentage_non');
$req->execute(array($c,$d,$e));
// Redirection du visiteur vers la page sondagepol
header('Location: sondagepol3.php');
}
else
{
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
// On ajoute un non dans le nombre de NON dans la table sondage_pol
$req = $bdd->prepare('UPDATE sondage_pol SET nb_non = (nb_non+1) WHERE questpoID = :questpoID');
$req->execute(array('questpoID' => $_POST['questpoID']));
// On ajoute une donnée dans la table historiquereponseidentifiant pour indiquer que le menbre à répodu à la questionID
$req = $bdd->prepare('INSERT INTO historiquereponseidentifiant (questionIDidentifiant,rep_non) VALUES (?, ?)');
$req->execute(array($_POST['questpoID'].$_SESSION['identifiant'],1));
// Redirection du visiteur vers la page sondagepol
header('Location: sondagepol3.php');
}
?>
</p> |
Partager