Foros del Web » Programando para Internet » PHP »

Concatenar variables de formulario

Estas en el tema de Concatenar variables de formulario en el foro de PHP en Foros del Web. Ya casi tengo el trabajo que debo presentar luchando, aprendiendo con la ayuda de ustedes. Solo me falta concatenar en una variable tres variables que ...
  #1 (permalink)  
Antiguo 26/07/2012, 22:50
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Concatenar variables de formulario

Ya casi tengo el trabajo que debo presentar luchando, aprendiendo con la ayuda de ustedes.

Solo me falta concatenar en una variable tres variables que vienen del formulario por favor les pido ayuda en esto ultimo la idea es:

Que en campo de la tabla GuiaMaestra quede almacenado asi:

BG123456PT

Donde Bg es una sigla selecionada y que viene de la variable CiudadOrigen al igual que PT, y el numero 123456 que viene de la varibale Numero.

ahora necesito que la el campo GuiaMaestra quede almacenado BG123456PT.


Gracias por su ayuda aqui parte del codigo por que no cabe todo:

Código PHP:
<?php require_once('../../../../Connections/conex.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;
}
}

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

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO guia (Numero, GuiaMaestra, FechaEnvio, Remitente, Destinatario, TipoEnvio, Transporte, FechaLlegada, ConfirmaRecepcion, Prioridad, EstadoEnvio, Observacion, CiudadOrigen, CiudadRecepcion) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Numero'], "text"),
              
GetSQLValueString($_POST['GuiaMaestra'], "text"),
                       
GetSQLValueString($_POST['FechaEnvio'], "date"),
                       
GetSQLValueString($_POST['Remitente'], "text"),
                       
GetSQLValueString($_POST['Destinatario'], "text"),
                       
GetSQLValueString($_POST['TipoEnvio'], "text"),
                       
GetSQLValueString($_POST['Transporte'], "text"),
                       
GetSQLValueString($_POST['FechaLlegada'], "date"),
                       
GetSQLValueString($_POST['ConfirmaRecepcion'], "text"),
                       
GetSQLValueString($_POST['Prioridad'], "text"),
                       
GetSQLValueString($_POST['EstadoEnvio'], "text"),
                       
GetSQLValueString($_POST['Observacion'], "text"),
                       
GetSQLValueString($_POST['CiudadOrigen'], "text"),
                       
GetSQLValueString($_POST['CiudadRecepcion'], "text"));

  
mysql_select_db($database_conex$conex);
  
$Result1 mysql_query($insertSQL$conex) or die(mysql_error());

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

$maxRows_NumeroConsecutivo 1;
$pageNum_NumeroConsecutivo 0;
if (isset(
$_GET['pageNum_NumeroConsecutivo'])) {
  
$pageNum_NumeroConsecutivo $_GET['pageNum_NumeroConsecutivo'];
}
$startRow_NumeroConsecutivo $pageNum_NumeroConsecutivo $maxRows_NumeroConsecutivo;

mysql_select_db($database_conex$conex);
$query_NumeroConsecutivo "SELECT * FROM consecutivos ORDER BY Numero DESC";
$query_limit_NumeroConsecutivo sprintf("%s LIMIT %d, %d"$query_NumeroConsecutivo$startRow_NumeroConsecutivo$maxRows_NumeroConsecutivo);
$NumeroConsecutivo mysql_query($query_limit_NumeroConsecutivo$conex) or die(mysql_error());
$row_NumeroConsecutivo mysql_fetch_assoc($NumeroConsecutivo);

if (isset(
$_GET['totalRows_NumeroConsecutivo'])) {
  
$totalRows_NumeroConsecutivo $_GET['totalRows_NumeroConsecutivo'];
} else {
  
$all_NumeroConsecutivo mysql_query($query_NumeroConsecutivo);
  
$totalRows_NumeroConsecutivo mysql_num_rows($all_NumeroConsecutivo);
}
$totalPages_NumeroConsecutivo ceil($totalRows_NumeroConsecutivo/$maxRows_NumeroConsecutivo)-1;

mysql_select_db($database_conex$conex);
$query_Prioridad "SELECT * FROM prioriodades";
$Prioridad mysql_query($query_Prioridad$conex) or die(mysql_error());
$row_Prioridad mysql_fetch_assoc($Prioridad);
$totalRows_Prioridad mysql_num_rows($Prioridad);

mysql_select_db($database_conex$conex);
$query_TipoDeEnvio "SELECT * FROM tipoenvio";
$TipoDeEnvio mysql_query($query_TipoDeEnvio$conex) or die(mysql_error());
$row_TipoDeEnvio mysql_fetch_assoc($TipoDeEnvio);
$totalRows_TipoDeEnvio mysql_num_rows($TipoDeEnvio);

mysql_select_db($database_conex$conex);
$query_Transporte "SELECT * FROM transporte";
$Transporte mysql_query($query_Transporte$conex) or die(mysql_error());
$row_Transporte mysql_fetch_assoc($Transporte);
$totalRows_Transporte mysql_num_rows($Transporte);

mysql_select_db($database_conex$conex);
$query_Ciudades "SELECT * FROM destinos";
$Ciudades mysql_query($query_Ciudades$conex) or die(mysql_error());
$row_Ciudades mysql_fetch_assoc($Ciudades);
$totalRows_Ciudades mysql_num_rows($Ciudades);
?>
  #2 (permalink)  
Antiguo 27/07/2012, 01:13
 
Fecha de Ingreso: julio-2012
Ubicación: Girona
Mensajes: 63
Antigüedad: 11 años, 9 meses
Puntos: 10
Respuesta: Concatenar variables de formulario

para concatenar strings se hace con el operador '.'
es decir:
$resultado=$variable1.$variable2.$variable3

Saludos
__________________
Por favor utilizad HIGHLIGHTS en los códigos insertados para que sean más legibles
  #3 (permalink)  
Antiguo 27/07/2012, 04:07
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Concatenar variables de formulario

Si eso hago pero me da el error Column 'GuiaMaestra' cannot be null

asi la he concatenado y nada que me funciona:


Código PHP:
<?php require_once('../../../../Connections/conex.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;
}
}

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

$cadena=$_POST['CiudadOrigen'].$_POST['Numero'].$_POST['CiudadRecepcion'];

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO guia (Numero, GuiaMaestra, FechaEnvio, Remitente, Destinatario, TipoEnvio, Transporte, FechaLlegada, ConfirmaRecepcion, Prioridad, EstadoEnvio, Observacion, CiudadOrigen, CiudadRecepcion) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Numero'], "text"),
                       
GetSQLValueString($_POST['GuiaMaestra'], "text"),
                       
GetSQLValueString($_POST['FechaEnvio'], "date"),
                       
GetSQLValueString($_POST['Remitente'], "text"),
                       
GetSQLValueString($_POST['Destinatario'], "text"),
                       
GetSQLValueString($_POST['TipoEnvio'], "text"),
                       
GetSQLValueString($_POST['Transporte'], "text"),
                       
GetSQLValueString($_POST['FechaLlegada'], "date"),
                       
GetSQLValueString($_POST['ConfirmaRecepcion'], "text"),
                       
GetSQLValueString($_POST['Prioridad'], "text"),
                       
GetSQLValueString($_POST['EstadoEnvio'], "text"),
                       
GetSQLValueString($_POST['Observacion'], "text"),
                       
GetSQLValueString($_POST['CiudadOrigen'], "text"),
                       
GetSQLValueString($_POST['CiudadRecepcion'], "text"));

  
mysql_select_db($database_conex$conex);
  
$Result1 mysql_query($insertSQL$conex) or die(mysql_error());



me podrian ayudar por favor
  #4 (permalink)  
Antiguo 27/07/2012, 04:15
 
Fecha de Ingreso: julio-2012
Ubicación: Girona
Mensajes: 63
Antigüedad: 11 años, 9 meses
Puntos: 10
Respuesta: Concatenar variables de formulario

Código PHP:
Ver original
  1. $insertSQL = sprintf("INSERT INTO guia (Numero, GuiaMaestra, FechaEnvio, Remitente, Destinatario, TipoEnvio, Transporte, FechaLlegada, ConfirmaRecepcion, Prioridad, EstadoEnvio, Observacion, CiudadOrigen, CiudadRecepcion) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
  2.                        GetSQLValueString($_POST['Numero'], "text"),
  3.                        GetSQLValueString($_POST['SiglaSeleccionada'].$_POST['Numero'].$_POST['CiudadOrigen'], "text"),
  4.                        GetSQLValueString($_POST['FechaEnvio'], "date"),
  5.                        GetSQLValueString($_POST['Remitente'], "text"),
  6.                        GetSQLValueString($_POST['Destinatario'], "text"),
  7.                        GetSQLValueString($_POST['TipoEnvio'], "text"),
  8.                        GetSQLValueString($_POST['Transporte'], "text"),
  9.                        GetSQLValueString($_POST['FechaLlegada'], "date"),
  10.                        GetSQLValueString($_POST['ConfirmaRecepcion'], "text"),
  11.                        GetSQLValueString($_POST['Prioridad'], "text"),
  12.                        GetSQLValueString($_POST['EstadoEnvio'], "text"),
  13.                        GetSQLValueString($_POST['Observacion'], "text"),
  14.                        GetSQLValueString($_POST['CiudadOrigen'], "text"),
  15.                        GetSQLValueString($_POST['CiudadRecepcion'], "text"));
nota que el post de sigla seleccionada, le he puesto el nombre de SiglaSeleccionada, porque no sé el nombre que le has puesto en el $_POST

Saludos
__________________
Por favor utilizad HIGHLIGHTS en los códigos insertados para que sean más legibles
  #5 (permalink)  
Antiguo 27/07/2012, 04:16
Avatar de gjx2  
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: Concatenar variables de formulario

El error no es por concatenación el asunto es que le estas pasando a GetSQLValueString un valor nulo en este caso $_POST['GuiaMaestra'] o sea no estas recuperando ese valor.
verifica bien.

Saludos!
  #6 (permalink)  
Antiguo 27/07/2012, 04:26
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Concatenar variables de formulario

Cita:
Iniciado por gjx2 Ver Mensaje
El error no es por concatenación el asunto es que le estas pasando a GetSQLValueString un valor nulo en este caso $_POST['GuiaMaestra'] o sea no estas recuperando ese valor.
verifica bien.

Saludos!
como recupero ese valor?
  #7 (permalink)  
Antiguo 27/07/2012, 04:29
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: Concatenar variables de formulario

Cita:
Iniciado por Zota Ver Mensaje
Si eso hago pero me da el error Column 'GuiaMaestra' cannot be null

asi la he concatenado y nada que me funciona:


Código PHP:
<?php require_once('../../../../Connections/conex.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;
}
}

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

$cadena=$_POST['CiudadOrigen'].$_POST['Numero'].$_POST['CiudadRecepcion'];

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO guia (Numero, GuiaMaestra, FechaEnvio, Remitente, Destinatario, TipoEnvio, Transporte, FechaLlegada, ConfirmaRecepcion, Prioridad, EstadoEnvio, Observacion, CiudadOrigen, CiudadRecepcion) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Numero'], "text"),
                       
GetSQLValueString($_POST['GuiaMaestra'], "text"),
                       
GetSQLValueString($_POST['FechaEnvio'], "date"),
                       
GetSQLValueString($_POST['Remitente'], "text"),
                       
GetSQLValueString($_POST['Destinatario'], "text"),
                       
GetSQLValueString($_POST['TipoEnvio'], "text"),
                       
GetSQLValueString($_POST['Transporte'], "text"),
                       
GetSQLValueString($_POST['FechaLlegada'], "date"),
                       
GetSQLValueString($_POST['ConfirmaRecepcion'], "text"),
                       
GetSQLValueString($_POST['Prioridad'], "text"),
                       
GetSQLValueString($_POST['EstadoEnvio'], "text"),
                       
GetSQLValueString($_POST['Observacion'], "text"),
                       
GetSQLValueString($_POST['CiudadOrigen'], "text"),
                       
GetSQLValueString($_POST['CiudadRecepcion'], "text"));

  
mysql_select_db($database_conex$conex);
  
$Result1 mysql_query($insertSQL$conex) or die(mysql_error());



me podrian ayudar por favor

Cambia esto:

Código PHP:

GetSQLValueString
($_POST['GuiaMaestra'], "text"), 
Por esto..

Código PHP:

GetSQLValueString
($cadena"text"), 
Ya que es es $cadena donde has hecho la concatenación ;)
__________________
>> Eleazan's Source
>> @Eleazan
  #8 (permalink)  
Antiguo 27/07/2012, 05:11
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Concatenar variables de formulario

gracias a todos con su ayuda quedo solucionado muchas gracias

Etiquetas: concatenar, formulario, html, mysql, sql, tabla, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:02.