Foros del Web » Programando para Internet » PHP »

ayuda con php

Estas en el tema de ayuda con php en el foro de PHP en Foros del Web. saludos foro tengo un problema he diseñado una pagina que muestra una informacion si introduces bien unos campos (cod_pro) y (contra), mi problema es este, ...
  #1 (permalink)  
Antiguo 10/11/2008, 05:54
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 9 meses
Puntos: 1
Pregunta ayuda con php

saludos foro tengo un problema he diseñado una pagina que muestra una informacion si introduces bien unos campos (cod_pro) y (contra), mi problema es este, quisiera que si se introducen ciertos numeros (26 por ejemplo) en el campo cod_pro me redireccione a una pagina x, y me muestre una info que esta en mi bd, el codigo que yo utilizo para mostra mi info es esta:

v_consulta.php
Código PHP:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>:: Venser S.A.C. :::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="estilo.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr valign="top" bgcolor="#FFFFFF"> 
    <td colspan="3"><font color="#FFFFFF"> 
      <?php include("superior.htm")?>
      </font></td>
  </tr>
  <tr valign="top" bgcolor="#FFFFFF"> 
    <td width="160"> <font color="#FFFFFF"> 
      <?php include("izquierda.htm")?>
      </font></td>
    <td width="440"><font color="#FFFFFF">&nbsp;
    
    <table width="420" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2"><table border="0" cellpadding="0" cellspacing="0" width="420">
      <!-- fwtable fwsrc="titulo.png" fwbase="titulo.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
      <tr>
        <td><img src="images/spacer.gif" width="115" height="1" border="0" alt="" /></td>
        <td><img src="images/spacer.gif" width="305" height="1" border="0" alt="" /></td>
        <td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
      </tr>
      <tr>
        <td rowspan="3"><img src="images/titulo_r1_c1.jpg" alt="" name="titulo_r1_c1" width="115" height="30" border="0" id="titulo_r1_c1" /></td>
        <td><img src="images/titulo_r1_c2.jpg" alt="" name="titulo_r1_c2" width="305" height="2" border="0" id="titulo_r1_c2" /></td>
        <td><img src="images/spacer.gif" width="1" height="2" border="0" alt="" /></td>
      </tr>
      <tr>
        <td background="images/titulo_r2_c2.jpg" class="titulo">Preliquidaciones</td>
        <td><img src="images/spacer.gif" width="1" height="25" border="0" alt="" /></td>
      </tr>
      <tr>
        <td><img src="images/titulo_r3_c2.jpg" alt="" name="titulo_r3_c2" width="305" height="3" border="0" id="titulo_r3_c2" /></td>
        <td><img src="images/spacer.gif" width="1" height="3" border="0" alt="" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="center" valign="middle" class="texto">RESULTADO DE LA CONSULTA</td>
  </tr>
  
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2"><?php 
      
require_once("autenticar_usr_fns.php");
 
$postor=$_POST[cod_postor];//
 
$contra=$_POST[contra];//'101'; //
 
$consulta_array=busca_empresa($postor,$contra);


?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="texto_nota">
  <tr>
    <td align="center" valign="middle" class="rojo">EL SALDO QUE FIGURA DEBERA DEPOSITARLO EN LA CTA/CTE ME</td>
  </tr>
    <tr>
    <td align="center" valign="middle" class="rojo">DEL BANCO DE CREDITO DEL PERU Nº 193-1194690-1-84</td>
  </tr>
    <tr>
    <td align="center" valign="middle" class="rojo">DE "LOS ANDES SERVICIOS CORPORATIVOS SAC"</td>
  </tr>
</table> 
  <table class="alt1" width="100%" cellpadding=4 border=0 cellspacing=1>
<?php
    
  
if (!is_array($consulta_array)){
     echo 
'No Se Puede mostrar ningun dato(s) para esta Empresa o el código y contraseña no es correcto.<br>';
       }
  else{
  
$color "#dfebf8"
  
$alinea="center";
  
$alinea1="left";
  
$enca="class=thead";
  
  echo 
"<tr $enca> <td><strong>Nº</strong></td>";
  echo 
"<td align=$alinea><strong>Postor</strong></td>";
  echo 
"<td align=$alinea><strong>Lote</strong></td>";
  echo 
"<td align=$alinea><strong>Base N°</strong></td>";
  echo 
"<td align=$alinea><strong>SALDO A CANCELAR US$</strong></td>";
  echo 
"</tr>";
      
      
$aa=1;
    
$datofi=0;
      foreach (
$consulta_array as $cu)
        {
         foreach (
$cu as $dato)
           if (
$color == '#dfebf8')
            
$color '#f5f5f5';
            
          else
          
$color '#dfebf8';
          
          echo 
"<tr bgcolor='$color'>";
          echo 
"<td align='$alinea'>".$aa."\n</td>";
          echo 
"<td align='$alinea'>".$cu[codigo]."\n</td>";
          echo 
"<td align='$alinea'>".$cu[lote]."</td>";
          echo 
"<td align='$alinea'>".$cu[codigo]."\n</td>";
            echo 
"<td align='$alinea'>".$cu[saldo]."\n</td>";
            echo 
"</tr>";
           
$aa++;
           
$datofi=$datofi+$cu[saldo];
        }
        
  }
   
?>
  <tr class="alt5">
    <td colspan="4" align="center">Saldo Total $ </td>
    <td align="center"> <?php echo $datofi?> </td>
  </tr>
</table>

</td>
    </tr>
  <tr>
    <td><a href="v_preliquidaciones.php">Regresar a consultar nuevamente</a></td>
    
  </tr>
</table>
      </td>
    <td width="160"> <font color="#FFFFFF"> 
    
    
      <?php include("derecha.htm")?>
      </font></td>
  </tr>
  <tr valign="top" bgcolor="#FFFFFF"> 
    <td colspan="3"><font color="#FFFFFF">&nbsp;
      <?php include("base.htm")?>
      </font></td>
  </tr>
</table>
</body>
</html>
mi codigo para autentificar

autenticar_usr_fns.php
Código PHP:
<?php
// 
require_once("conectardb_fns.php");

function 
busca_empresa($postor$contra)
{
if (!
$postor==' ')
      return 
false;
  
  
$conn db_connect();
  if (!
$conn)
    return 
false;
  
  
$query "select * from postores where codigo='$postor' and contra='$contra'";
  
      
$result = @mysql_query($query);
      if (!
$result)
     return 
false;
    
$num_proyectos = @mysql_num_rows($result);
     if (
$num_proyectos==0)
         return 
false;
         
$result db_resultados_array($result);
       return 
$result;
}

function 
db_resultados_array($resultado)
{
     
$res_array = array();
    for (
$count=0$row = @mysql_fetch_array($resultado); $count++)
    
$res_array[$count] = $row;
    return 
$res_array;
}


?>
mi problema es como puedo hacer eso ?, gracias por la ayuda que me den...
  #2 (permalink)  
Antiguo 10/11/2008, 09:05
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: ayuda con php

No encontré los campos que mencionas en tu página .

Pero si son solo campos en un formulario, lo único que necesitas es recibir el formulario, tomar los valores y con una condicional mostrar uno u otro contenido.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 10/11/2008, 09:56
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 9 meses
Puntos: 1
Respuesta: ayuda con php

me estaba olvidando la pagina para validar es esta:

v_preliquidaciones.htm
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
@import url("estilo.css");
-->
</style>
</head>

<body>
<table width="420" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td colspan="2"><table border="0" cellpadding="0" cellspacing="0" width="420">
        <!-- fwtable fwsrc="titulo.png" fwbase="titulo.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
        <tr> 
          <td><img src="images/spacer.gif" width="115" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="305" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
        </tr>
        <tr> 
          <td rowspan="3"><img name="titulo_r1_c1" src="images/titulo_r1_c1.jpg" width="115" height="30" border="0" alt=""></td>
          <td><img name="titulo_r1_c2" src="images/titulo_r1_c2.jpg" width="305" height="2" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="2" border="0" alt=""></td>
        </tr>
        <tr> 
          <td background="images/titulo_r2_c2.jpg" class="titulo">Preliquidaciones</td>
          <td><img src="images/spacer.gif" width="1" height="25" border="0" alt=""></td>
        </tr>
        <tr> 
          <td><img name="titulo_r3_c2" src="images/titulo_r3_c2.jpg" width="305" height="3" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="3" border="0" alt=""></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" class="texto">Introduce tu Nro de Postor y Fact./Boleta</td>
  </tr>
  <tr> 
    <td colspan="2" class="texto">&nbsp;</td>
  </tr>
  <tr> 
    <td colspan="2" class="texto">&nbsp;</td>
  </tr>
  <tr valign="top"> 
    <td colspan="2" align="center" class="texto"><form name="form1" method="post" action="v_consulta.php">
        <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#990002">
        <tr>
          <td><table border="0" align="center" cellpadding="0" cellspacing="8">
              <tr>
                <td width="200" align="right" valign="middle" class="texto"><div align="right"><strong>Numero de postor:</strong></div></td>
                <td width="200"><input type="text" name="cod_postor" id="cod_postor"></td>
              </tr>
              <tr>
                <td align="right" valign="middle" class="textoderecha"><div align="right">Contrase&ntilde;a :</div></td>
                <td class="texto"><input type="password" name="contra" id="textfield"></td>
              </tr>
              <tr>
                <td class="texto">&nbsp;</td>
                <td class="texto"><input type="submit" name="button" id="button" value="Consutar"></td>
              </tr>
          </table></td>
        </tr>
      </table>
        </form> </td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html> 
podrias ponerme un ejemplo por favor de lo que me acabas de decir ??
  #4 (permalink)  
Antiguo 10/11/2008, 10:11
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: ayuda con php

Veo que en la variable $postor estás recuperando el valor del formulario, entonces basta con una condicional:
Código php:
Ver original
  1. if ($postor==26) {
  2.      /* Hacer esto en caso de que escriban 26 */
  3. }
Y si son más posibilidades un switch .
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #5 (permalink)  
Antiguo 10/11/2008, 11:41
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 9 meses
Puntos: 1
Respuesta: ayuda con php

disculpa la pregunta, ese codigo que me acabas de poner, en que parte tendria que colocarla o mejor dicho en que pagina colocaria ese codigo? y una ultima pregunta, si en caso que solo fueran 02 numeros (26 y 129 por ejemplo) o sea si ingreso como numeros 26 o 129 como haria para que se redireccione a una pagina x con un switch ?, gracias por la ayuda que me den...
  #6 (permalink)  
Antiguo 10/11/2008, 12:07
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: ayuda con php

Debería ser en la página que recibe el formulario, o sea, v_consulta.php.

Depende, diría yo, si lo que quieres es redireccionar sin realizar ningún otro procesamiento con el formulario bastaría con modificar la cabecera(header) para redireccionar, pero, eso sí, sin enviar ninguna salida HTML.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #7 (permalink)  
Antiguo 10/11/2008, 15:27
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 9 meses
Puntos: 1
Respuesta: ayuda con php

Aver bueno esto es lo que hice:
v_consulta.php
Código PHP:
<?php
if ($cod_postor==26) {
header ("Location: v_consulta2.php");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>:: Venser S.A.C. :::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="estilo.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr valign="top" bgcolor="#FFFFFF"> 
    <td colspan="3"><font color="#FFFFFF"> 
      <?php include("superior.htm")?>
      </font></td>
  </tr>
  <tr valign="top" bgcolor="#FFFFFF"> 
    <td width="160"> <font color="#FFFFFF"> 
      <?php include("izquierda.htm")?>
      </font></td>
    <td width="440"><font color="#FFFFFF">&nbsp;
    
    <table width="420" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2"><table border="0" cellpadding="0" cellspacing="0" width="420">
      <!-- fwtable fwsrc="titulo.png" fwbase="titulo.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
      <tr>
        <td><img src="http://www.forosdelweb.com/images/spacer.gif" width="115" height="1" border="0" alt="" /></td>
        <td><img src="http://www.forosdelweb.com/images/spacer.gif" width="305" height="1" border="0" alt="" /></td>
        <td><img src="http://www.forosdelweb.com/images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
      </tr>
      <tr>
        <td rowspan="3"><img src="http://www.forosdelweb.com/images/titulo_r1_c1.jpg" alt="" name="titulo_r1_c1" width="115" height="30" border="0" id="titulo_r1_c1" /></td>
        <td><img src="http://www.forosdelweb.com/images/titulo_r1_c2.jpg" alt="" name="titulo_r1_c2" width="305" height="2" border="0" id="titulo_r1_c2" /></td>
        <td><img src="http://www.forosdelweb.com/images/spacer.gif" width="1" height="2" border="0" alt="" /></td>
      </tr>
      <tr>
        <td background="http://www.forosdelweb.com/images/titulo_r2_c2.jpg" class="titulo">Preliquidaciones</td>
        <td><img src="http://www.forosdelweb.com/images/spacer.gif" width="1" height="25" border="0" alt="" /></td>
      </tr>
      <tr>
        <td><img src="http://www.forosdelweb.com/images/titulo_r3_c2.jpg" alt="" name="titulo_r3_c2" width="305" height="3" border="0" id="titulo_r3_c2" /></td>
        <td><img src="http://www.forosdelweb.com/images/spacer.gif" width="1" height="3" border="0" alt="" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="center" valign="middle" class="texto">RESULTADO DE LA CONSULTA</td>
  </tr>
  
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2"><?php 
      
require_once("autenticar_usr_fns.php");
 
$postor=$_POST[cod_postor];//
 
$contra=$_POST[contra];//'101'; //
 
$consulta_array=busca_empresa($postor,$contra);


?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="texto_nota">
  <tr>
    <td align="center" valign="middle" class="rojo">EL SALDO QUE FIGURA DEBERA DEPOSITARLO EN LA CTA/CTE ME</td>
  </tr>
    <tr>
    <td align="center" valign="middle" class="rojo">DEL BANCO DE CREDITO DEL PERU Nº 193-1194690-1-84</td>
  </tr>
    <tr>
    <td align="center" valign="middle" class="rojo">DE "LOS ANDES SERVICIOS CORPORATIVOS SAC"</td>
  </tr>
</table> 
  <table class="alt1" width="100%" cellpadding=4 border=0 cellspacing=1>
<?php
    
  
if (!is_array($consulta_array)){
     echo 
'No Se Puede mostrar ningun dato(s) para esta Empresa o el código y contraseña no es correcto.<br>';
       }
  else{
  
$color "#dfebf8"
  
$alinea="center";
  
$alinea1="left";
  
$enca="class=thead";
  
  echo 
"<tr $enca> <td><strong>Nº</strong></td>";
  echo 
"<td align=$alinea><strong>Postor</strong></td>";
  echo 
"<td align=$alinea><strong>Lote</strong></td>";
  echo 
"<td align=$alinea><strong>Base N°</strong></td>";
  echo 
"<td align=$alinea><strong>SALDO A CANCELAR US$</strong></td>";
  echo 
"</tr>";
      
      
$aa=1;
    
$datofi=0;
      foreach (
$consulta_array as $cu)
        {
         foreach (
$cu as $dato)
           if (
$color == '#dfebf8')
            
$color '#f5f5f5';
            
          else
          
$color '#dfebf8';
          
          echo 
"<tr bgcolor='$color'>";
          echo 
"<td align='$alinea'>".$aa."\n</td>";
          echo 
"<td align='$alinea'>".$cu[codigo]."\n</td>";
          echo 
"<td align='$alinea'>".$cu[lote]."</td>";
          echo 
"<td align='$alinea'>".$cu[codigo]."\n</td>";
            echo 
"<td align='$alinea'>".$cu[saldo]."\n</td>";
            echo 
"</tr>";
           
$aa++;
           
$datofi=$datofi+$cu[saldo];
        }
        
  }
   
?>
  <tr class="alt5">
    <td colspan="4" align="center">Saldo Total $ </td>
    <td align="center"> <?php echo $datofi?> </td>
  </tr>
</table>

</td>
    </tr>
  <tr>
    <td><a href="v_preliquidaciones.php">Regresar a consultar nuevamente</a></td>
    
  </tr>
</table>
      </td>
    <td width="160"> <font color="#FFFFFF"> 
    
    
      <?php include("derecha.htm")?>
      </font></td>
  </tr>
  <tr valign="top" bgcolor="#FFFFFF"> 
    <td colspan="3"><font color="#FFFFFF">&nbsp;
      <?php include("base.htm")?>
      </font></td>
  </tr>
</table>
</body>
</html>
pero no me redirecciono salio este mensaje:

Notice: Undefined variable: cod_postor in c:\archivos de programa\easyphp1-8\www\venser\v_consulta.php on line 2
cual es mi error ??
  #8 (permalink)  
Antiguo 10/11/2008, 15:36
Avatar de srsombrero  
Fecha de Ingreso: marzo-2008
Mensajes: 128
Antigüedad: 16 años
Puntos: 0
Respuesta: ayuda con php

Cita:
Iniciado por dannysoft Ver Mensaje
Aver bueno esto es lo que hice:
v_consulta.php
[PHP]
<?php
if ($cod_postor==26) {
header ("Location: v_consulta2.php");
}
?>
¿De donde sacas $cod_postor? Hiciste $_GET ["cod_postor"] ?

No me digas que usas register globals.....


  #9 (permalink)  
Antiguo 10/11/2008, 16:10
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 9 meses
Puntos: 1
Respuesta: ayuda con php

$cod_postor es un campo que esta en la pagina v_preliquidaciones.htm que cuando ingreso un numero de postor (26 por ejemplo) lo compara con un campo de la bd y si es igual me muestra unos datos en otra parte de la pag web (v_consulta.php)
  #10 (permalink)  
Antiguo 10/11/2008, 16:37
Avatar de srsombrero  
Fecha de Ingreso: marzo-2008
Mensajes: 128
Antigüedad: 16 años
Puntos: 0
Respuesta: ayuda con php

Cita:
Iniciado por dannysoft Ver Mensaje
$cod_postor es un campo que esta en la pagina v_preliquidaciones.htm que cuando ingreso un numero de postor (26 por ejemplo) lo compara con un campo de la bd y si es igual me muestra unos datos en otra parte de la pag web (v_consulta.php)
Por lo que veo es que vos no estas recibiendo nunca de la pagina v_preliquidaciones.htm un parametro que se pase a v_consulta.php

Deberias para que pueda comparar php esa variable definirla en algun momento con algo....porque ahora esta vacia....

En v_preliquidaciones.htm

Código HTML:
<a href="v_consulta.php?Codigo=.......EL CODIGO......">Ir al detalle</a> 
y en v_consulta.php

Código PHP:
$cod_postor $_GET["Codigo"
Saludos
  #11 (permalink)  
Antiguo 10/11/2008, 20:05
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: ayuda con php

Hola, dannysoft, como te dijo srsombrero debes recuperar primero el valor de la variable. O sea mueve la línea:
Código php:
Ver original
  1. $postor = $_POST["cod_postor"];
A la primera línea.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #12 (permalink)  
Antiguo 12/11/2008, 16:26
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 9 meses
Puntos: 1
Respuesta: ayuda con php

o sea:

Código PHP:
$postor $_POST["cod_postor"]; 
lo coloco en la primera linea de v_consulta.php ?
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 05:36.