Ir para conteúdo
Fórum Script Brasil
  • 0

Registrar emails iguais em listas diferentes


gsq_queiroz

Pergunta

Tenho um pequeno sistema onde, você cria listas para envio de emails marketing, para fazer o cadastro de emails, primeiro tem que selecionar a lista no qual deseja fazer o envio, os emails cadastrados são vinculados a lista escolhida. Existe um bloqueio para que não haja duplicidade de emails no BD, mas não é possível cadastrar o mesmo e-mail em listas diferentes;

Fiz o sistema utilizando ferramentas do Dreamweaver, sei que não é bom programar assim, mais estou com o tempo muito curto;

Esse é o código que estou usando para o cadastro:

<?php require_once('Connections/projeto1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
//------------------------------Inserir manualmente com sucesso----------------------------//-------

$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="email_nao_cadastrado.php";
  $loginUsername = $_POST['email'];
  $LoginRS__query = sprintf("SELECT email FROM email WHERE email=%s", GetSQLValueString($loginUsername, "text"));
  mysql_select_db($database_projeto1, $projeto1);
  $LoginRS=mysql_query($LoginRS__query, $projeto1) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);

 
  if($loginFoundUser){
    $MM_qsChar = "?";
    //append the username to the redirect page
    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
    header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}
//----------------------------------------//-------------------------------------------//------------

//----------------------Condição email já cadastrado-----------------------------//-------------------
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO email (id_lista, email) VALUES (%s, %s)",
                       GetSQLValueString($_POST['id_lista'], "int"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_projeto1, $projeto1);
  $Result1 = mysql_query($insertSQL, $projeto1) or die(mysql_error());

  $insertGoTo = "email_cadastrado.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

//Sei que é nessa parte acima que devo fazer a alteração, mais não sei como montar o código aqui.


<form method="post" name="form2" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right"><span class="style10">Email:</span></td>
      <td><input type="text" name="email" value="" size="32"></td>
      <td><input type="submit" value="Cadastrar"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <input type="hidden" name="id_lista" value="<?php echo $row_rs_listas['id']; ?>">
  <input type="hidden" name="MM_insert" value="form2">
</form>

Não sei como criar um condição que não permita cadastro de um mesmo email em uma lista, mais que permita o mesmo email em uma lista diferente. Alguém tem alguma dica ou um material que me ajude a fazer essa alteração??

Editado por gsq_queiroz
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0
<?php require_once('Connections/projeto1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
//------------------------------Inserir manualmente com sucesso----------------------------//-------

$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="email_nao_cadastrado.php";
  $loginUsername = $_POST['email'];
  $LoginRS__query = sprintf("SELECT * FROM email WHERE email=%s", GetSQLValueString($loginUsername, "text"), " and id_lista=%s", GetSQLValueString($_POST['id_lista'], "int"));
  mysql_select_db($database_projeto1, $projeto1);
  $LoginRS=mysql_query($LoginRS__query, $projeto1) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);

  if($loginFoundUser){
    $MM_qsChar = "?";
    //append the username to the redirect page
    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
    header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}
//----------------------------------------//-------------------------------------------//------------

//----------------------Condição email já cadastrado-----------------------------//-------------------
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO email (id_lista, email) VALUES (%s, %s)",
                       GetSQLValueString($_POST['id_lista'], "int"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_projeto1, $projeto1);
  $Result1 = mysql_query($insertSQL, $projeto1) or die(mysql_error());

  $insertGoTo = "email_cadastrado.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
//----------------------------------------//-------------------------------------------//------------
$colname_rs_listas = "-1";
if (isset($_GET['id'])) {
  $colname_rs_listas = $_GET['id'];
}
mysql_select_db($database_projeto1, $projeto1);
$query_rs_listas = sprintf("SELECT * FROM listas WHERE id = %s", GetSQLValueString($colname_rs_listas, "int"));
$rs_listas = mysql_query($query_rs_listas, $projeto1) or die(mysql_error());
$row_rs_listas = mysql_fetch_assoc($rs_listas);
$totalRows_rs_listas = mysql_num_rows($rs_listas);

$colname_rs_email = "-1";
if (isset($_GET['id_lista'])) {
  $colname_rs_email = $_GET['id_lista'];
}
mysql_select_db($database_projeto1, $projeto1);
$query_rs_email = sprintf("SELECT * FROM email WHERE id_lista = %s", GetSQLValueString($colname_rs_email, "int"));
$rs_email = mysql_query($query_rs_email, $projeto1) or die(mysql_error());
$row_rs_email = mysql_fetch_assoc($rs_email);
$totalRows_rs_email = mysql_num_rows($rs_email);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Projeto1</title>
<style>
 body {
	background:#FFF;
	margin:0;
	padding:0;
	border:0;
	font-weight: bold;
	background-color: #ECF5EC;
	background-image: url(img/fundo3.png);
	background-repeat: no-repeat;
	background-size:100% 100%;
    -webkit-background-size: 100% 100%;
    -o-background-size: 100% 100%;
   -khtml-background-size: 100% 100%;
   -moz-background-size: 100% 100%
	}
</style>
<style type="text/css">
<!--
.style10 {
	color: #42864A;
	font-size: 24px;
}
.style11 {
	color: #42864A;
	font-size: 18px;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onLoad="MM_preloadImages('img/smtp_02.png','img/email_02.png','img/Cam_01.png')">
<p>&nbsp;</p>
<table width="1246">
  <tr>
    <td width="1309"><table width="1344" align="center">
      <tr>
        <td width="43">&nbsp;</td>
        <td width="151"><a href="menu.php"><img src="img/menu.png" width="103" height="57" /></a></td>
        <td width="130"><a href="lista.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image9','','img/Cam_01.png',1)"><img src="img/Cam_02.png" name="Image9" width="118" height="79" border="0"></a></td>
        <td width="30"><img src="img/setinha.png" width="19" height="55" /></td>
        <td width="130"><img src="img/Cad_02.png" width="118" height="79"></td>
        <td width="30"><img src="img/setinha.png" alt="" width="19" height="55" /></td>
        <td width="131"><a href="conf_smtp.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image4','','img/smtp_02.png',1)"><img src="img/smtp_01.png" name="Image4" width="118" height="79" border="0" id="Image4" /></a></td>
        <td width="30"><img src="img/setinha.png" alt="" width="19" height="55" /></td>
        <td width="498"><a href="enviar_email.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','img/email_02.png',1)"><img src="img/email_01.png" name="Image5" width="118" height="79" border="0" id="Image5" /></a></td>
        <td width="127">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>

<p>&nbsp;</p>

<form method="post" name="form2" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right"><span class="style10">Email:</span></td>
      <td><input type="text" name="email" value="" size="32"></td>
      <td><input type="submit" value="Cadastrar"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <input type="hidden" name="id_lista" value="<?php echo $row_rs_listas['id']; ?>">
  <input type="hidden" name="MM_insert" value="form2">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="200" align="center">
  <tr>
    <td><div align="center" class="style10">Selecione sua lista de e-mails</div></td>
  </tr>
  <tr>
    <td><table width="600" align="center">

      <tr>
        <td><form action="upload_listaemails.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
            <table width="400" border="0" align="center">
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td><label>
                  <input type="file" name="arquivo" id="arquivo" />
                  <input type="submit" name="button" id="button" value="Enviar" />
                  <input name="id" type="hidden" id="id" value="<?php echo $row_rs_listas['id']; ?>" />
                  <input name="id_lista" type="hidden" id="id_lista" value="<?php echo $row_rs_listas['id']; ?>" />
                 </label></td>
                <td>&nbsp;</td>
              </tr>
            </table>
        </form></td>
      </tr>

    </table></td>
  </tr>
  <tr>
    <td><div align="center" class="style11">Arquivo em formato txt.</div></td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="200" border="0" align="center">
  <tr>
    <td><form name="form3" method="post" action="">
      <?php
 
//Conexão e consulta ao Mysql
mysql_connect('localhost','root','root') or die(mysql_error());
mysql_select_db('projeto1') or die(mysql_error());
$qry = mysql_query("SELECT * FROM email");
 
//Pegando os nomes dos campos
$num_fields = mysql_num_fields($qry);//Obtém o número de campos do resultado
 
for($i = 0;$i<$num_fields; $i++){//Pega o nome dos campos
	$fields[] = mysql_field_name($qry,$i);
}
 
//Montando o cabeçalho da tabela
$table = '<table border="1"><tr>';
 
for($i = 0;$i < $num_fields; $i++){
	$table .= '<th>'.$fields[$i].'</th>';
}
 
//Montando o corpo da tabela
$table .= '<tbody>';
while($r = mysql_fetch_array($qry)){
	$table .= '<tr>';
	for($i = 0;$i < $num_fields; $i++){
		$table .= '<td>'.$r[$fields[$i]].'</td>';
	}
	$table .= '</tr>';
}
 
//Finalizando a tabela
$table .= '</tbody></table>';
 
//Imprimindo a tabela
echo $table;
 
?>
    </form></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($rs_listas);

mysql_free_result($rs_email);
?>

Editado por gsq_queiroz
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...