Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/05/2014, 12:56
mortisdj
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 10 años
Puntos: 0
Problema enviar formulario php+mysql

Buenas, tengo un formulario el cual envía un mail, todo funciona ok menos una cosa.

A la hora de enviar el mail, me envia la ID del centro en vez de enviarme el nombre del centro.

Os explico un poco como tengo las tablas.

La tabla tblcentro tiene los siguientes campos...

intcentro, strNombre, strLocalidad, refProvincia, strDireccion, strCP, strTelefono, intLibros, fchFecha, strObervaciones....

la tabla tblusuarios tiene los siguientes campos...

intId, strNombre, strApellidos, strEspecialidad, intCentro, strLocalidadCentro, strEmail, intTelefono, strMensaje, intActivo, strPassword....

El caso, es que en el mail me envía intCentro y me envía la ID del centro, pero yo quiero que en vez de eso me envíe el strNombre de la tabla tblcentro de la ID que corresponda.

No se si me he explicado bien...

Vamos, si el la id 1 pertenece al centro Centro de prueba, pues me envia 1 en vez de enviarme Centro de prueba.

Os dejo el código a ver si me podeis ayudar. El código lleva bastante mas, todo lo cual funciona bien, pero en eso me estoy atragantando.

Gracias.

Código:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

mysql_select_db($database_conexion, $conexion);
//$query_DatosCentros = "SELECT * FROM tblcentro ORDER BY tblcentro.refProvincia ASC,  tblcentro.strLocalidad ASC , strNombre ASC";
$query_DatosCentros = "SELECT tblcentro.*,tblprovincias.provincia, tblprovincias.id FROM
tblcentro
Inner Join tblprovincias ON tblcentro.refProvincia = tblprovincias.id ORDER BY tblprovincias.provincia ASC, tblcentro.strLocalidad ASC, tblcentro.strNombre ASC";
$DatosCentros = mysql_query($query_DatosCentros, $conexion) or die(mysql_error());
$row_DatosCentros = mysql_fetch_assoc($DatosCentros);
$totalRows_DatosCentros = mysql_num_rows($DatosCentros);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formulario")) {
  $insertSQL = sprintf("INSERT INTO tblusuarios (strNombre, strApellidos, strEspecialidad, intCentro,  strEmail, intTelefono, strMensaje, intOrigen) VALUES (%s, %s, %s, %s, %s, %s, %s, 0)",
                       GetSQLValueString($_POST['strNombre'], "text"),
                       GetSQLValueString($_POST['strApellidos'], "text"),
                       GetSQLValueString($_POST['strEspecialidad'], "text"),
                       GetSQLValueString($_POST['intCentro'], "int"),        
                       GetSQLValueString($_POST['strEmail'], "text"),
                       GetSQLValueString($_POST['intTelefono'], "int"),
                       GetSQLValueString($_POST['strMensaje'], "text"));

  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

  $insertGoTo = "profesores-registro-ok.php";
  /*if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }*/
  header(sprintf("Location: %s", $insertGoTo));
	$asunto = 'Formulario de Contacto Enviado desde profesores registrados';
	$destinatario = '[email protected]';
    $mensaje = "Hola admin,<br />";
    $mensaje .= "se ha enviado un formulario de contacto desde profesores resgistrados con lo siguientes datos:<br /><br />";    $mensaje .= "- Nombre: ".$_POST['strNombre']."<br />";
    $mensaje .= "- Apellidos: ".$_POST['strApellidos']."<br />";
    $mensaje .= "- Especialidad: ".$_POST['strEspecialidad']."<br />";
    $mensaje .= "- Centro: ".$_POST['intCentro']."<br />";
    $mensaje .= "- Telefono: ".$_POST['intTelefono']."<br />";
    $mensaje .= "- Email: ".$_POST['strEmail']."<br />";
    $mensaje .= "- Mensaje: ".nl2br($_POST['strMensaje'])."<br /><br />";	
	EnviarCorreoHTML($destinatario,$asunto,utf8_decode($mensaje));
}
?>