<?php
include ('logue.php'); 
include ('entete2.php');

$sql = "SELECT mail FROM matgraph_users WHERE id='$idlogin'";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 


$req = "SELECT id FROM matgraph_newsletter WHERE adresse='$row[mail]' ORDER by id ASC";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);

if($num > 0) {
echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("profil.php");
-->
</script>'; 
exit; }

$requete = "INSERT INTO matgraph_newsletter VALUES('','$row[mail]')";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("profil.php");
-->
</script>'; 


?>