Foros del Web » Programando para Internet » PHP »

Formulario que actualiza varias tablas

Estas en el tema de Formulario que actualiza varias tablas en el foro de PHP en Foros del Web. Hola mi problema es el siguiente: Tengo un formulario para la insercion de datos de unos partidos de futbol, en dicho formulario registro quien jugo ...
  #1 (permalink)  
Antiguo 06/08/2013, 12:03
 
Fecha de Ingreso: agosto-2013
Mensajes: 1
Antigüedad: 10 años, 8 meses
Puntos: 0
Formulario que actualiza varias tablas

Hola mi problema es el siguiente:
Tengo un formulario para la insercion de datos de unos partidos de futbol, en dicho formulario registro quien jugo y como quedo. al dar actualizar, me guarda bien los datos en la tabla resultados, pero lo que yo quiero es que tmb en la tabla partidos me actualice los partidos ganados de los equipos, los perdidos,los empatados as-i como los puntos...
estoy dando vuelvtas y vueltas y no se como hacerlo....

Aqui mi codigo......


Código PHP:
Ver original
  1. <?php require_once('Connections/ligadeportiva.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  40.   $insertSQL = sprintf("INSERT INTO calendario (Id_Liga, Id_Equipo_Local, Id_Equipo_Visitante, Numero_Jornada, Fecha, Goles_local, Goles_visitante, Id_colegiado, Id_campo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
  41.                        GetSQLValueString($_POST['Id_Liga'], "int"),
  42.                        GetSQLValueString($_POST['Id_Equipo_Local'], "int"),
  43.                        GetSQLValueString($_POST['Id_Equipo_Visitante'], "int"),
  44.                        GetSQLValueString($_POST['Numero_Jornada'], "int"),
  45.                        GetSQLValueString($_POST['Fecha'], "date"),
  46.                        GetSQLValueString($_POST['Goles_local'], "int"),
  47.                        GetSQLValueString($_POST['Goles_visitante'], "int"),
  48.                        GetSQLValueString($_POST['Id_colegiado'], "int"),
  49.                        GetSQLValueString($_POST['Id_campo'], "int"));
  50.  
  51.   mysql_select_db($database_ligadeportiva, $ligadeportiva);
  52.   $Result1 = mysql_query($insertSQL, $ligadeportiva) or die(mysql_error());
  53. }
  54.  
  55. $colname_Recordset1 = "-1";
  56. if (isset($_GET['Id_Liga'])) {
  57.   $colname_Recordset1 = $_GET['Id_Liga'];
  58. }
  59. mysql_select_db($database_ligadeportiva, $ligadeportiva);
  60. $query_Recordset1 = sprintf("SELECT * FROM liga WHERE Id_Liga = %s", GetSQLValueString($colname_Recordset1, "int"));
  61. $Recordset1 = mysql_query($query_Recordset1, $ligadeportiva) or die(mysql_error());
  62. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  63. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  64.  
  65. $colname_Recordset2 = "-1";
  66. if (isset($_GET['Id_Liga'])) {
  67.   $colname_Recordset2 = $_GET['Id_Liga'];
  68. }
  69. mysql_select_db($database_ligadeportiva, $ligadeportiva);
  70. $query_Recordset2 = sprintf("SELECT * FROM equipo WHERE Id_Liga = %s", GetSQLValueString($colname_Recordset2, "int"));
  71. $Recordset2 = mysql_query($query_Recordset2, $ligadeportiva) or die(mysql_error());
  72. $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  73. $totalRows_Recordset2 = mysql_num_rows($Recordset2);
  74.  
  75. mysql_select_db($database_ligadeportiva, $ligadeportiva);
  76. $query_Recordset3 = "SELECT * FROM campo";
  77. $Recordset3 = mysql_query($query_Recordset3, $ligadeportiva) or die(mysql_error());
  78. $row_Recordset3 = mysql_fetch_assoc($Recordset3);
  79. $totalRows_Recordset3 = mysql_num_rows($Recordset3);
  80.  
  81. mysql_select_db($database_ligadeportiva, $ligadeportiva);
  82. $query_Recordset4 = "SELECT * FROM colegiado";
  83. $Recordset4 = mysql_query($query_Recordset4, $ligadeportiva) or die(mysql_error());
  84. $row_Recordset4 = mysql_fetch_assoc($Recordset4);
  85. $totalRows_Recordset4 = mysql_num_rows($Recordset4);
  86. ?>
  87. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  88. <html xmlns="http://www.w3.org/1999/xhtml">
  89. <head>
  90. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  91. <title>Documento sin título</title>
  92. </head>
  93.  
  94. <body>
  95. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  96.   <table align="center">
  97.     <tr valign="baseline">
  98.       <td nowrap="nowrap" align="right">Id_Liga:</td>
  99.       <td><input type="text" name="Id_Liga" value="<?php echo $row_Recordset1['Id_Liga']; ?>" size="32" /></td>
  100.     </tr>
  101.     <tr valign="baseline">
  102.       <td nowrap="nowrap" align="right">Id_Equipo_Local:</td>
  103.       <td><label for="Id_Equipo_Local"></label>
  104.         <select name="Id_Equipo_Local" id="Id_Equipo_Local">
  105.           <?php
  106. do {  
  107. ?>
  108.           <option value="<?php echo $row_Recordset2['Id_Equipo']?>"><?php echo $row_Recordset2['Nombre']?></option>
  109.           <?php
  110. } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
  111.   $rows = mysql_num_rows($Recordset2);
  112.   if($rows > 0) {
  113.       mysql_data_seek($Recordset2, 0);
  114.       $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  115.   }
  116. ?>
  117.       </select></td>
  118.     </tr>
  119.     <tr valign="baseline">
  120.       <td nowrap="nowrap" align="right">Id_Equipo_Visitante:</td>
  121.       <td><label for="Id_Equipo_Visitante"></label>
  122.         <select name="Id_Equipo_Visitante" id="Id_Equipo_Visitante">
  123.           <?php
  124. do {  
  125. ?>
  126.           <option value="<?php echo $row_Recordset2['Id_Equipo']?>"><?php echo $row_Recordset2['Nombre']?></option>
  127.           <?php
  128. } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
  129.   $rows = mysql_num_rows($Recordset2);
  130.   if($rows > 0) {
  131.       mysql_data_seek($Recordset2, 0);
  132.       $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  133.   }
  134. ?>
  135.       </select></td>
  136.     </tr>
  137.     <tr valign="baseline">
  138.       <td nowrap="nowrap" align="right">Numero_Jornada:</td>
  139.       <td><input type="text" name="Numero_Jornada" value="" size="32" /></td>
  140.     </tr>
  141.     <tr valign="baseline">
  142.       <td nowrap="nowrap" align="right">Fecha:</td>
  143.       <td><input type="text" name="Fecha" value="0000-00-00" size="32" /></td>
  144.     </tr>
  145.     <tr valign="baseline">
  146.       <td nowrap="nowrap" align="right">Goles_local:</td>
  147.       <td><input type="text" name="Goles_local" value="" size="32" /></td>
  148.     </tr>
  149.     <tr valign="baseline">
  150.       <td nowrap="nowrap" align="right">Goles_visitante:</td>
  151.       <td><input type="text" name="Goles_visitante" value="" size="32" /></td>
  152.     </tr>
  153.     <tr valign="baseline">
  154.       <td nowrap="nowrap" align="right">Id_colegiado:</td>
  155.       <td><label for="Id_colegiado"></label>
  156.         <select name="Id_colegiado" id="Id_colegiado">
  157.           <?php
  158. do {  
  159. ?>
  160.           <option value="<?php echo $row_Recordset4['Id_Colegiado']?>"><?php echo $row_Recordset4['Nombre completo']?></option>
  161.           <?php
  162. } while ($row_Recordset4 = mysql_fetch_assoc($Recordset4));
  163.   $rows = mysql_num_rows($Recordset4);
  164.   if($rows > 0) {
  165.       mysql_data_seek($Recordset4, 0);
  166.       $row_Recordset4 = mysql_fetch_assoc($Recordset4);
  167.   }
  168. ?>
  169.       </select></td>
  170.     </tr>
  171.     <tr valign="baseline">
  172.       <td nowrap="nowrap" align="right">Id_campo:</td>
  173.       <td><label for="Id_campo"></label>
  174.         <select name="Id_campo" id="Id_campo">
  175.           <?php
  176. do {  
  177. ?>
  178.           <option value="<?php echo $row_Recordset3['Id_campo']?>"><?php echo $row_Recordset3['Nombre']?></option>
  179.           <?php
  180. } while ($row_Recordset3 = mysql_fetch_assoc($Recordset3));
  181.   $rows = mysql_num_rows($Recordset3);
  182.   if($rows > 0) {
  183.       mysql_data_seek($Recordset3, 0);
  184.       $row_Recordset3 = mysql_fetch_assoc($Recordset3);
  185.   }
  186. ?>
  187.       </select></td>
  188.     </tr>
  189.     <tr valign="baseline">
  190.       <td nowrap="nowrap" align="right">&nbsp;</td>
  191.       <td><input type="submit" value="Insertar registro" /></td>
  192.     </tr>
  193.   </table>
  194.   <input type="hidden" name="MM_insert" value="form1" />
  195. </form>
  196. <p>&nbsp;</p>
  197. </body>
  198. </html>
  199. <?php
  200. mysql_free_result($Recordset1);
  201.  
  202. mysql_free_result($Recordset2);
  203.  
  204. mysql_free_result($Recordset3);
  205.  
  206. mysql_free_result($Recordset4);
  207. ?>

Última edición por Triby; 06/08/2013 a las 16:30 Razón: Código en Highlight
  #2 (permalink)  
Antiguo 06/08/2013, 16:33
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Formulario que actualiza varias tablas

Ya tienes esto:

Código PHP:
Ver original
  1. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  2.   $insertSQL = sprintf("INSERT INTO calendario (Id_Liga, Id_Equipo_Local, Id_Equipo_Visitante, Numero_Jornada, Fecha, Goles_local, Goles_visitante, Id_colegiado, Id_campo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
  3.                        GetSQLValueString($_POST['Id_Liga'], "int"),
  4.                        GetSQLValueString($_POST['Id_Equipo_Local'], "int"),
  5.                        GetSQLValueString($_POST['Id_Equipo_Visitante'], "int"),
  6.                        GetSQLValueString($_POST['Numero_Jornada'], "int"),
  7.                        GetSQLValueString($_POST['Fecha'], "date"),
  8.                        GetSQLValueString($_POST['Goles_local'], "int"),
  9.                        GetSQLValueString($_POST['Goles_visitante'], "int"),
  10.                        GetSQLValueString($_POST['Id_colegiado'], "int"),
  11.                        GetSQLValueString($_POST['Id_campo'], "int"));
  12.  
  13.   mysql_select_db($database_ligadeportiva, $ligadeportiva);
  14.   $Result1 = mysql_query($insertSQL, $ligadeportiva) or die(mysql_error());
  15.   /**
  16.    *************** Aquí es donde debes ejecutar las consultas adicionales *********
  17.    */
  18. }

Si tienes algún problema para crear las consultas, sería útil ver la estructura de tus tablas para poder sugerirte algo.
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: formulario, html, mysql, registro, select, sql, tabla, tablas
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:04.