Comunidad de diseño web y desarrollo en internet online

Formulario, envio a base de datos & e-mail

Citar            
MensajeEscrito el 26 Nov 2008 05:37 pm
Hola muchachos, tengo una consutilla por hacer, antes que nada quiero explicar que en PHP y MySQL soy un 0 a la izquierda.
Me encargaron un rediseño para un buscador, el sistema ya está creado desde hace unos años atras, el problemá está en que ahora quieren que cuando se registre un anuncio desde el formulario, sea enviado un mail de aviso al administrador.
Explico un poco sobre cómo hicieron el formulario:
es un formulario que tiene por action:

Código :

<?php echo $editFormAction; ?>

y esto es lo que viene en el header:

Código :

<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addMessage")) {
  $insertSQL = sprintf("INSERT INTO cliente (firstName, lastName, country, state, email, website,title,keywords, comment, `date`, marker,type) VALUES (%s, %s,%s ,%s, %s,%s,%s, %s, %s, %s, %s,1)",
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['country'], "text"),
                  GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['website'], "text"),
                       GetSQLValueString($_POST['title'], "text"),
                  GetSQLValueString($_POST['keywords'], "text"),
                  GetSQLValueString($_POST['comment'], "text"),
                       GetSQLValueString($_POST['date'], "text"),
                       GetSQLValueString($_POST['date2'], "date"));

  mysql_select_db($database, $accelgbook);
  $Result1 = mysql_query($insertSQL, $accelgbook) or die(mysql_error());

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

He intentado añadir estas lineas antes del "?>", pero nada :P :

Código :

$destinatario = "[email protected]";
mail($destinatario, $Result1);


Espero haber sido lo suficientemente claro para ver si me pueden echar una mano con este asuntito.
Desde ya, gracias por el interes.

Por BlackMage

37 de clabLevel



 

firefox
Citar            
MensajeEscrito el 27 Nov 2008 09:27 pm
Debido a la gran cantidad de respuestas que tuve ( :roll: ) y luego de mucho café, llegé a hacer esto:
, en el código del header, antes de que finalize, hice esto:

Código :

  
...
$insertGoTo = "ingreso_added.php?date=".$HTTP_POST_VARS['date']."";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
  header(sprintf("Location: %s", $insertGoTo));
  
$campo1="Nombre: ";
$name = $_POST['firstName'];
$cuerpo .= $campo1.$name."\n";
$campo2="Apellido: ";
$apellido = $_POST['lastName'];
$cuerpo .= $campo2.$apellido."\n";
$campo3="State: ";
$state = $_POST['state'];
$cuerpo .= $campo3.$state."\n";
$campo4="Email: ";
$email = $_POST['email'];
$cuerpo .= $campo4.$email."\n";
$campo5="Website: ";
$website = $_POST["website"];
$cuerpo .= $campo5.$website."\n";
$campo6="Title: ";
$title = $_POST['title'];
$cuerpo .= $campo6.$title."\n";
$campo7="Comment: ";
$comment = $_POST['comment'];
$cuerpo .= $campo7.$comment."\n";
$destinatario = "[email protected]" . ', ';
//$destinatario .= '[email protected]';
$asunto = "Hay un nuevo agregado en el DirectorioPeruanoUSA";
mail($destinatario, $asunto, $cuerpo, "From: $email");

}
?>


y ya :lol: salió, todo ese código PHP lo saqué del clásico formulario que pongo en casi todas mis páginas :wink: .

Pero surgió otro problema... no sé cómo cambiar el cotejamiento en mi báse de datos, he visto unos cuantos post, pero aun no estoy seguro, tengo miedito.
Lo que vi fue esto:

Código :

ALTER DATABASE 'mi_tabla' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin


Pero la persona dice que tuvo un error, y no sé muy bien, podrían recomendarme algo más?


Gracias!

Por BlackMage

37 de clabLevel



 

firefox
Citar            
MensajeEscrito el 28 Nov 2008 12:26 am
muchos de nosotros estamos ocupados no es excusarnos pero he de hay y siempre te recomiendo buscar ayuda cuando ya no encuentres solucion aprendes mas ;-) no lo tomes a mal

Por talcual

686 de clabLevel



 

Colombia

firefox
Citar            
MensajeEscrito el 28 Nov 2008 01:02 am
Siii!!!... lo sé, por eso que es puse en "()" esa carita :lol:
Y pues si, estuve buscando e investigando, hasta lograr hacerlo!, lo único que me falta es eso de los UTF, pero igual voy a seguir buscando, y si alguien por aqui tiene consejos, son bienvenidos :wink:

Por BlackMage

37 de clabLevel



 

firefox
Citar            
MensajeEscrito el 28 Nov 2008 05:31 am
utf8_encode y utf8_decode busca las referencias en php.net y saludos

Por talcual

686 de clabLevel



 

Colombia

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.