Foros del Web » Programando para Internet » PHP »

Post y get en una misma pagina? No me guarda registro

Estas en el tema de Post y get en una misma pagina? No me guarda registro en el foro de PHP en Foros del Web. Si alguien puede darme una mano con este problema que esta vez ni logro figurar de que se trata: Código PHP: <?php include( "libreria/engine.php" ); ...
  #1 (permalink)  
Antiguo 26/10/2011, 13:01
 
Fecha de Ingreso: junio-2009
Mensajes: 88
Antigüedad: 14 años, 9 meses
Puntos: 4
Post y get en una misma pagina? No me guarda registro

Si alguien puede darme una mano con este problema que esta vez ni logro figurar de que se trata:

Código PHP:
<?php
include("libreria/engine.php");

if(
$_POST)
{
    
$lugar $_POST["txtLugar"];
    
$nombre $_POST["txtNombre"];
    
$latitud $_POST["txtLatitud"];
    
$longitud $_POST["txtLongitud"];
    
    
guardarCaso($lugar$nombre$latitud$longitud);
}

if(
$_GET)
{
    
$cod $_GET['id'];
    
mostrarCasoParaModificar($cod);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link href="estilo_mapa.css" rel="stylesheet" type="text/css" />
        <script type="application/javascript" src="js/Validacion.js"></script>
        <title>Casos de Colera - Modificar</title>
        <script language="javascript" type="text/javascript">
        function mostrar(){
        alert('hey');
        }
        </script>
        <style type="text/css">
<!--
#apDiv1 {
    position:absolute;
    left:45px;
    top:156px;
    width:900px;
    height:119px;
    z-index:1;
}
-->
        </style>
</head>
    <body>
        <div id="apDiv1" align="center">
        <form name="form1" method="post" action="Modificar.php">
          <table width="600" border="0">
            <tr>
              <td width="200" nowrap>&nbsp;</td>
              <td width="200" align="center" ><span class="formato_rojo_centro"> Modificar Caso de Colera</span></td>
              <td width="200">
              </td>
            </tr>
            <tr>
              <td width="200" nowrap><div align="right" class="formato_Texto">Codigo</div></td>
              <td align="center" >
                  <?php 
                $id 
$_GET["id"]; 
                
$arrayModificable mostrarCasoParaModificar($id);
                echo 
'   
                <input name=txtCod" value="'
.$arrayModificable[cod].'"  disabled="disabled"
                type="text" class="formato_rojo_centro" id="txtCod" size="22">
                '
;
                
?>
              </td>
              <td width="200">
              </td>
            </tr>
            <tr>
              <td width="200" nowrap class="formato_Texto"><div align="right">Lugar</div></td>
              <td width="200">
                <label>
                <?php 
                $id 
$_GET["id"]; 
                
$arrayModificable mostrarCasoParaModificar($id);
                echo 
'   
                <input name=txtLugar" value="'
.$arrayModificable[lugar].'" 
                type="text" class="formato_rojo_centro" id="txtLugar" size="22">
                '
;
                
?>
              </label></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="200" nowrap class="formato_Texto"><div align="right">Nombre</div></td>
              <td width="200"><label>
                
                <?php 
                $id 
$_GET["id"]; 
                
$arrayModificable mostrarCasoParaModificar($id);
                echo 
'  
                <input name="txtNombre" type="text" value="'
.$arrayModificable[nombre].'" 
                class="formato_rojo_centro" id="txtNombre" size="22">
                '
;
                
?>
              </label></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="200" nowrap class="formato_Texto"><div align="right">Fecha</div></td>
              <td width="200"><label>
                 <?php 
                $id 
$_GET["id"]; 
                
$arrayModificable mostrarCasoParaModificar($id);
                echo 
'  
                <input name="txtFecha" type="text" value="'
.$arrayModificable[fecha].'" 
                class="formato_rojo_centro" id="txtFecha" size="22">
                '
;
                
?>
              </label></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="200" nowrap class="formato_Texto"><div align="right">Latitud</div></td>
              <td width="200"><label>
                 <?php 
                $id 
$_GET["id"]; 
                
$arrayModificable mostrarCasoParaModificar($id);
                echo 
'  
                <input name="txtFecha" type="text" value="'
.$arrayModificable[latitud].'" 
                class="formato_rojo_centro" id="txtFecha" size="22">
                '
;
                
?>
              </label></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="200" nowrap class="formato_Texto"><div align="right">Longitud</div></td>
              <td width="200"><label>
                   <?php 
                $id 
$_GET["id"]; 
                
$arrayModificable mostrarCasoParaModificar($id);
                echo 
'  
                <input name="txtLongitud" type="text" value="'
.$arrayModificable[longitud].'" 
                class="formato_rojo_centro" id="txtLongitud" size="22">
                '
;
                
?>
              </label></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td colspan="3" ><div align="center">
                <label>
                <input type="submit" name="modificar" id="modificar" value="Modificar">
                </label>
              </div></td>
            </tr>
            <tr>
              <td colspan="3" id="comentario">&nbsp;</td>
            </tr>
          </table>
          </form>
    </div>
        <?php
        
include("header.php");
        
?>
</body>
</html>
No es mucho aunque se vea largo, es solo una tabla que recibe de la base de datos la informacion y la pone en los input´s. Entonces quiero hacer que se guarden en la base de datos, al darle a enviar. Pero No lo hace.

En la pagina engine, estas son las funciones que tengo:

Código PHP:

<?php
include("Conexion.php");

function 
mostrarCasos(){
    
$sql="SELECT * FROM puntos";
    
$res=@mysql_query($sql);
    if(!
$res){
    echo 
" fallo";
    }
    
$variable;
    echo 
"<div id='listado_Codigos'>";
    while (
$fila=mysql_fetch_array($res)){
    
$variable "{$fila['0']}";
    
$variable2 "{$fila['2']}";
    echo 
"<a href='Modificar.php?id={$fila['0']}' align='center'><span class='cuadritos' align='center'>$variable2</span></a></br>";
    }
    echo 
"</div>";
}

function 
mostrarCasoParaModificar($cod){
    
$sql "select * from puntos where cod = $cod";
    
$resultados mysql_query($sql);
    
$filas mysql_num_rows($resultados);
    global 
$cod$lugar$nombre$fecha$latitud$longitud;
        while(
$fila mysql_fetch_array($resultados)){
            
$cod $fila['0'];
            
$lugar $fila['1'];
            
$nombre $fila['2'];
            
$fecha $fila['3'];
            
$latitud $fila['4'];
            
$longitud $fila['5'];
            
        }
    return array(
'cod'=>$cod'lugar'=>$lugar'nombre'=>$nombre'fecha'=>$fecha'latitud'=>$latitud'longitud'=>$longitud);
    
}

function 
guardarCaso($lugar$nombre$latitud$longitud){
    
$fecha date("y-m-d");
    
$sql "INSERT INTO puntos(lugar, nombre, fecha, latitud, longitud) VALUES ('$lugar', '$nombre', '$fecha', '$latitud', '$longitud')";
    
mysql_query($sql);
}
La insercion funciona en otra pagina que tenia. No se si es que no se pueda usar post y get al mismo tiempo.
  #2 (permalink)  
Antiguo 26/10/2011, 13:06
Avatar de h2swider  
Fecha de Ingreso: julio-2007
Ubicación: Ciudad de Buenos Aires
Mensajes: 932
Antigüedad: 16 años, 8 meses
Puntos: 194
Respuesta: Post y get en una misma pagina? No me guarda registro

primero que nada si se puede usar post y get al mismo tiempo, asi que ese no es el problema

otra cosa, deberías preguntar por isset($_POST['foo']) isset($_GET['foo'])

Tienes que debugear el código para ver que esta ocurriendo, intenta ir poniendo echos o var_dump por donde piensas que va el flujo del código, así te das una mejor idea de lo que esta ocurriendo
__________________
Codifica siempre como si la persona que finalmente mantedra tu código sea un psicópata violento que sabe donde vives
  #3 (permalink)  
Antiguo 26/10/2011, 13:37
Avatar de Patriarka  
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 2 meses
Puntos: 288
Respuesta: Post y get en una misma pagina? No me guarda registro

hace esto:
Código PHP:
Ver original
  1. echo '<pre>';
  2. var_dump($_GET);
  3. var_dump($_POST);
  4. echo '</pre>';
  #4 (permalink)  
Antiguo 26/10/2011, 13:52
 
Fecha de Ingreso: junio-2009
Mensajes: 88
Antigüedad: 14 años, 9 meses
Puntos: 4
Respuesta: Post y get en una misma pagina? No me guarda registro

Gracias por responder.

Este fue el resultado que me arrojo:

Código PHP:
Ver original
  1. Hola [B]Ramemberto Garcia[/B], bienvenido a PHP
  2.  
  3. array(0) {
  4. }
  5. array(5) {
  6.   ["txtLugar\""]=>
  7.   string(13) "Cayo Levantao"
  8.   ["txtNombre"]=>
  9.   string(17) "Ramemberto Garcia"
  10.   ["txtFecha"]=>
  11.   string(9) "18.462025"
  12.   ["txtLongitud"]=>
  13.   string(10) "-70.729691"
  14.   ["modificar"]=>
  15.   string(0) ""
  16. }

Última edición por sterlingdiazd; 26/10/2011 a las 14:24
  #5 (permalink)  
Antiguo 26/10/2011, 14:25
 
Fecha de Ingreso: junio-2009
Mensajes: 88
Antigüedad: 14 años, 9 meses
Puntos: 4
Respuesta: Post y get en una misma pagina? No me guarda registro

Algo raro que sale ahi es
Cita:
["modificar"]=>
Este es el error que me manda cuando le doy a enviar con la informacion cambiada

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a4002248/public_html/libreria/engine.php on line 23

Etiquetas: post
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 06:48.