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

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

$req = "SELECT id FROM matgraph_newsletter WHERE adresse='$row2[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 ) {
$sql = "DELETE FROM matgraph_newsletter WHERE adresse='$row2[mail]'";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());

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

?>