Encontré un script de un boletin de novedades que me gustó mucho, ya que los usuarios pueden suscribirse o desuscribirse... Funciona correctamente, envia los e-mails y todo, el problema es el siguiente: ingreso a este correo (ejem)
[email protected] y me dice que fue agregado y es verdad, lo agrega. Luego pongo el mismo y le doy a suscribirme y en teoria me tendria que decir que el correo ya esta registrado, pero no, me dice que se registró exitosamente :S:S
También, si le pongo el mismo correo y pongo desuscribirme me dice que ese correo no existe en la base de datos por eso no lo puede borrar y no me lo borra :(:(
Les dejo es script....
Tabla SQL
Código PHP:
CREATE TABLE `tabla_boletin` (
`id` bigint(20) NOT NULL auto_increment,
`email` varchar(100) NOT NULL default '',
`fecha` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) TYPE=MyISAM AUTO_INCREMENT=1;
suscribir.php
Código PHP:
<?php
if($seguro_del) {
include("conexion.php");
$result = @mysql_query("SELECT email FROM `tabla_boletin` WHERE `email` LIKE ' $email '");
if(mysql_num_rows($result) != 0) {
$sql = @mysql_query("DELETE FROM `tabla_boletin` WHERE `email`=' $email '");
$msg = " El correo electr?nico se ha removido, no recibir? nuestras novedades. ";
} else {
$msg = " El email que solicitaste para darlo de baja no existe en la base de datos. ";
} } elseif($seguro_ins) {
include("conexion.php");
$sql = "SELECT email FROM `tabla_boletin` WHERE `email` LIKE ' $email '";
$result = mysql_query($sql);
if(mysql_num_rows($result) != 0) { $msg = " El email que indicaste para la suscripci?n ya se encuentra registrado en la base de datos. "; } else {
if (!ereg("^[^@]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,}$", $email)) { $msg =" Tu correo electr?nico no existe o esta mal escrito. "; } else {
$fecha = date("Y/n/d H:i:s");
$sql = "INSERT INTO `tabla_boletin` SET `email`=' $email ', `fecha`=' $fecha '";
$result = mysql_query($sql);
$msg = " La suscripci?n fue un ?xito, recibir?s las novedades de nuestro sitio. ";
} } }
?>
<html>
<head>
<title>Suscribir al bolet?n</title>
</head>
<body>
<div align="center">
<?php if($msg) { ?>
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td><div align="center" class="texto_gral"><?=$msg;?></div></td>
</tr>
<tr>
<td><div align="center"><a href="javascript:window.close()"><strong>cerrar ventana</strong></a></div></td>
</tr>
</table>
<? } else { ?>
<form action="suscribir.php" method="post" name="" id="">
<table width="200" border="0" cellspacing="2" cellpadding="0">
<tr>
<td><input name="email" type="text" id="email" value="tu correo electrónico" size="25">
</td>
</tr>
<tr>
<td> <div align="right">
<input name="seguro_ins" type="submit" id="seguro_ins" value="suscr?bete">
<input name="seguro_del" type="submit" id="seguro_del" value="desinscribir">
</div></td>
</tr>
</table>
</form>
<? } ?>
</div>
</body>
</html>
enviarboletin.php
Código PHP:
<html>
<head>
<title>Sistema de bolet?n :: Env?o de emails</title>
</head>
<body>
<?
if($seguro_env) {
include("conexion.php");
$sql = mysql_query("SELECT * FROM `tabla_boletin`");
$n = 1;
while($row = mysql_fetch_array($sql)) {
$asunto ="Bolet?n NO.1";
$headers = "MIME-Version: 1.0\r \n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r \n";
$headers .= "From: \"Bolet?n de Dise-web\" <[email protected]>\r \n";
if(!$mensaje) { echo "No haz escrito el bolet?n!"; } else {
mail("".$row["email"]."","$asunto","$mensaje\n\n","$headers");
echo "<div>".$n++.". Enviado email a <b>".$row["email"]."</b><br></div>";
}
}
} else {
?>
<form action="enviarboletin.php" method="post" name="" id="">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><font size="4" face="tahoma, Arial, verdana"><strong>Puedes usar HTML
para el boletín.</strong></font></td>
</tr>
<tr>
<td><textarea name="mensaje" cols="50" rows="5" id="mensaje"></textarea></td>
</tr>
<tr>
<td><input name="seguro_env" type="submit" id="seguro_env" value="Enviar"></td>
</tr>
</table>
</form>
<? } ?>
</body>
</html>
Gracias y espero que me puedan ayudar... (no esta el archivo conexion.php lo tengo guardado y ahora se los doy)
conexion.php
Código PHP:
$hosting = "localhost" ;
$usuario = "usuarios" ;
$clave = "clave" ;
$db = "base de datos" ;
$conectar = mysql_connect($hosting,$usuario,$clave) ; mysql_select_db($db,$conectar) ;
$resp = mysql_query("select * from TABLA") ;