<?
include 'enteteindex.php'; ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Newsletter</title>
</head>

<body>
<br><br><div align="center">
<?
// Connexion à MySql
include 'config.php';

// Affichage du Nombre d'inscrits
$inscrits = db_mysql_Query("SELECT COUNT(*) AS nbre_inscrits FROM matgraph_newsletter");
$nbre_inscrits = mysql_fetch_array($inscrits); 

echo 'Il y a ' . $nbre_inscrits['nbre_inscrits'] . ' inscrits à la Newsletter';
// Déconnexion de Mysql

?>
<br />
<form method='post' action'inscription5.php' name = 'newsletter'>
<input type='text' name='adressem'>
<br />
<input type="radio" name="action" value="inscription" checked="checked" /> S'inscrire
<br />
<input type="radio" name="action" value="desinscription" /> Se Désinscrire
<br />
<input type="submit" value="Valider">
</form>
<?
// Connexion à Mysql



$adressem = $_POST["adressem"];
$action = $_POST["action"];

if(!empty($adressem)) {
	$sql = "SELECT adresse FROM matgraph_newsletter WHERE adresse ='$adressem' ";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
	$num = mysql_num_rows($res);
	if($action == "inscription") {
		if ( $num == 0 ) {
		$requete = "INSERT INTO matgraph_newsletter VALUES('','$adressem')";
		$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
		}
	}
	else {
		if ( $num !== 0 ) {
		$sql = "DELETE FROM matgraph_newsletter WHERE adresse = '$adressem'";
		$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
		}
		else {
		echo '<script language=javascript> alert ("Vous n\'etes pas inscrit");</script>';
		}
	}
}

?>
</body>
</html>
