Foros del Web » Programando para Internet » PHP »

Insertar registros 2 tablas

Estas en el tema de Insertar registros 2 tablas en el foro de PHP en Foros del Web. Buenas tengo un formulario que me debería insertar registros en dos tablas distintas . Tabla persoas y tabla tags. El problema está en que solo ...
  #1 (permalink)  
Antiguo 23/05/2008, 05:36
 
Fecha de Ingreso: abril-2008
Mensajes: 70
Antigüedad: 16 años
Puntos: 0
Insertar registros 2 tablas

Buenas tengo un formulario que me debería insertar registros en dos tablas distintas . Tabla persoas y tabla tags.

El problema está en que solo me inserta en la tabla tags en la tabla persoas no hace modificacion alguna, el codigo es este

Código PHP:
<?php require_once('Connections/bd_contactos.php'); ?>
<?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"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO persoas (cod_prsa, cod_nme, cod_aplds, txt_nome_aclme, txt_aplds_aclme, txt_tlfno_trbllo, txt_tlfno_dmclo, txt_tlfno_mbl, txt_fx, cod_crro_1, cod_crro_2, cod_url, cod_ra, cod_nmr_ra, cod_nmr_pso, cod_endrzo_info_pls, cod_cp, cod_pblcn, cod_prvnca, cod_pis) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['cod_prsa'], "int"),
                       
GetSQLValueString($_POST['cod_nme'], "text"),
                       
GetSQLValueString($_POST['cod_aplds'], "text"),
                       
GetSQLValueString($_POST['txt_nome_aclme'], "text"),
                       
GetSQLValueString($_POST['txt_aplds_aclme'], "text"),
                       
GetSQLValueString($_POST['txt_tlfno_trbllo'], "text"),
                       
GetSQLValueString($_POST['txt_tlfno_dmclo'], "text"),
                       
GetSQLValueString($_POST['txt_tlfno_mbl'], "text"),
                       
GetSQLValueString($_POST['txt_fx'], "text"),
                       
GetSQLValueString($_POST['cod_crro_1'], "text"),
                       
GetSQLValueString($_POST['cod_crro_2'], "text"),
                       
GetSQLValueString($_POST['cod_url'], "text"),
                       
GetSQLValueString($_POST['cod_ra'], "text"),
                       
GetSQLValueString($_POST['cod_nmr_ra'], "text"),
                       
GetSQLValueString($_POST['cod_nmr_pso'], "text"),
                       
GetSQLValueString($_POST['cod_endrzo_info_pls'], "text"),
                       
GetSQLValueString($_POST['cod_cp'], "text"),
                       
GetSQLValueString($_POST['cod_pblcn'], "text"),
                       
GetSQLValueString($_POST['cod_prvnca'], "text"),
                       
GetSQLValueString($_POST['cod_pis'], "text"));
    
$insertSQL sprintf("INSERT INTO tags (cod_tag, txt_tag, tpo_tag) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['cod_tag'], "int"),
                       
GetSQLValueString($_POST['txt_tag'], "text"),
                       
GetSQLValueString($_POST['tpo_tag'], "text"));

  
mysql_select_db($database_bd_contactos$bd_contactos);
  
$Result1 mysql_query($insertSQL$bd_contactos) or die(mysql_error());
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
.Estilo1 {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-weight: bold;
}
-->
</style>
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction?>">
  <table align="center">
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Nome:</span></td>
      <td><input type="text" name="cod_nme" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Apelidos:</span></td>
      <td><input type="text" name="cod_aplds" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Alcume nome:</span></td>
      <td><input type="text" name="txt_nome_aclme" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Alcume apelidos:</span></td>
      <td><input type="text" name="txt_aplds_aclme" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Tlf traballo:</span></td>
      <td><input type="text" name="txt_tlfno_trbllo" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Tlf domicilio:</span></td>
      <td><input type="text" name="txt_tlfno_dmclo" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Tlf m&oacute;bil:</span></td>
      <td><input type="text" name="txt_tlfno_mbl" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Fax:</span></td>
      <td><input type="text" name="txt_fx" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">email n&ordm;1:</span></td>
      <td><input type="text" name="cod_crro_1" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Email n&ordm;2:</span></td>
      <td><input type="text" name="cod_crro_2" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">P&aacute;xina web:</span></td>
      <td><input type="text" name="cod_url" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Domicilio:</span></td>
      <td><input type="text" name="cod_ra" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">N&ordm; domicilio:</span></td>
      <td><input type="text" name="cod_nmr_ra" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">N&ordm; Piso:</span></td>
      <td><input type="text" name="cod_nmr_pso" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Cod_endrzo_info_pls:</span></td>
      <td><input type="text" name="cod_endrzo_info_pls" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">CP:</span></td>
      <td><input type="text" name="cod_cp" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Poboaci&oacute;n:</span></td>
      <td><input type="text" name="cod_pblcn" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Provincia:</span></td>
      <td><input type="text" name="cod_prvnca" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Pa&iacute;s:</span></td>
      <td><input type="text" name="cod_pis" value="" size="32"></td>
    </tr>
  <td nowrap align="right"><span class="Estilo1">Tag:</span></td>
      <td><input type="text" name="txt_tag" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="Estilo1">Tipo Tag:</span></td>
      <td><input type="text" name="tpo_tag" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><div align="center">
        <input type="submit" value="Insertar registro">
      </div></td>
    </tr>
  </table>
  <input type="hidden" name="cod_prsa" value="">
    <input type="hidden" name="cod_tag" value="">
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>
Tengo algo mal que hace que no reaccione la tabla persoas?
  #2 (permalink)  
Antiguo 23/05/2008, 06:06
 
Fecha de Ingreso: abril-2008
Mensajes: 70
Antigüedad: 16 años
Puntos: 0
Respuesta: Insertar registros 2 tablas

Ya lo subsane le cambié el nombre a la 2ª instruccion

Código PHP:
<?php require_once('Connections/bd_contactos.php'); ?>
<?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"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO persoas (cod_prsa, cod_nme, cod_aplds, txt_nome_aclme, txt_aplds_aclme, txt_tlfno_trbllo, txt_tlfno_dmclo, txt_tlfno_mbl, txt_fx, cod_crro_1, cod_crro_2, cod_url, cod_ra, cod_nmr_ra, cod_nmr_pso, cod_endrzo_info_pls, cod_cp, cod_pblcn, cod_prvnca, cod_pis) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['cod_prsa'], "int"),
                       
GetSQLValueString($_POST['cod_nme'], "text"),
                       
GetSQLValueString($_POST['cod_aplds'], "text"),
                       
GetSQLValueString($_POST['txt_nome_aclme'], "text"),
                       
GetSQLValueString($_POST['txt_aplds_aclme'], "text"),
                       
GetSQLValueString($_POST['txt_tlfno_trbllo'], "text"),
                       
GetSQLValueString($_POST['txt_tlfno_dmclo'], "text"),
                       
GetSQLValueString($_POST['txt_tlfno_mbl'], "text"),
                       
GetSQLValueString($_POST['txt_fx'], "text"),
                       
GetSQLValueString($_POST['cod_crro_1'], "text"),
                       
GetSQLValueString($_POST['cod_crro_2'], "text"),
                       
GetSQLValueString($_POST['cod_url'], "text"),
                       
GetSQLValueString($_POST['cod_ra'], "text"),
                       
GetSQLValueString($_POST['cod_nmr_ra'], "text"),
                       
GetSQLValueString($_POST['cod_nmr_pso'], "text"),
                       
GetSQLValueString($_POST['cod_endrzo_info_pls'], "text"),
                       
GetSQLValueString($_POST['cod_cp'], "text"),
                       
GetSQLValueString($_POST['cod_pblcn'], "text"),
                       
GetSQLValueString($_POST['cod_prvnca'], "text"),
                       
GetSQLValueString($_POST['cod_pis'], "text"));
    
$insertSQL2 sprintf("INSERT INTO tags (cod_tag, txt_tag, tpo_tag) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['cod_tag'], "int"),
                       
GetSQLValueString($_POST['txt_tag'], "text"),
                       
GetSQLValueString($_POST['tpo_tag'], "text"));

  
mysql_select_db($database_bd_contactos$bd_contactos);
  
$Result1 mysql_query($insertSQL$bd_contactos) or die(mysql_error());
  
   
mysql_select_db($database_bd_contactos$bd_contactos);
  
$Result12 mysql_query($insertSQL2$bd_contactos) or die(mysql_error());
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
.Estilo1 {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-weight: bold;
}
-->
</style>
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction?>">
  <table align="center">
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Nome:</span></td>
      <td><input type="text" name="cod_nme" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Apelidos:</span></td>
      <td><input type="text" name="cod_aplds" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Alcume nome:</span></td>
      <td><input type="text" name="txt_nome_aclme" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Alcume apelidos:</span></td>
      <td><input type="text" name="txt_aplds_aclme" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Tlf traballo:</span></td>
      <td><input type="text" name="txt_tlfno_trbllo" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Tlf domicilio:</span></td>
      <td><input type="text" name="txt_tlfno_dmclo" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Tlf m&oacute;bil:</span></td>
      <td><input type="text" name="txt_tlfno_mbl" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Fax:</span></td>
      <td><input type="text" name="txt_fx" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">email n&ordm;1:</span></td>
      <td><input type="text" name="cod_crro_1" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Email n&ordm;2:</span></td>
      <td><input type="text" name="cod_crro_2" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">P&aacute;xina web:</span></td>
      <td><input type="text" name="cod_url" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Domicilio:</span></td>
      <td><input type="text" name="cod_ra" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">N&ordm; domicilio:</span></td>
      <td><input type="text" name="cod_nmr_ra" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">N&ordm; Piso:</span></td>
      <td><input type="text" name="cod_nmr_pso" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Cod_endrzo_info_pls:</span></td>
      <td><input type="text" name="cod_endrzo_info_pls" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">CP:</span></td>
      <td><input type="text" name="cod_cp" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Poboaci&oacute;n:</span></td>
      <td><input type="text" name="cod_pblcn" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Provincia:</span></td>
      <td><input type="text" name="cod_prvnca" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"><span class="Estilo1">Pa&iacute;s:</span></td>
      <td><input type="text" name="cod_pis" value="" size="32"></td>
    </tr>
  <td nowrap align="right"><span class="Estilo1">Tag:</span></td>
      <td><input type="text" name="txt_tag" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="Estilo1">Tipo Tag:</span></td>
      <td><input type="text" name="tpo_tag" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><div align="center">
        <input type="submit" value="Insertar registro">
      </div></td>
    </tr>
  </table>
  <input type="hidden" name="cod_prsa" value="">
    <input type="hidden" name="cod_tag" value="">
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>
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 13:15.