Foros del Web » Programando para Internet » PHP »

Como funciona esto

Estas en el tema de Como funciona esto en el foro de PHP en Foros del Web. Hola a todos, en este momento tengo una web modular, el archivo index esta con este codigo: Código PHP: <?php if( $_GET [ id ] ==  ...
  #1 (permalink)  
Antiguo 23/10/2007, 22:03
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Exclamación Como funciona esto

Hola a todos, en este momento tengo una web modular, el archivo index esta con este codigo:

Código PHP:
<?php
if($_GET[id] == "") {
    include(
"modulos/inicio.php"); 
} else {
    if(
file_exists("modulos/".$_GET[id].".php")) {
        include(
"modulos/".$_GET[id].".php");
    } else {
        include(
"modulos/error.php");
    }
}
?>
hasta aqui ningun problema, es mas creo paginas como por ejemplo otra.php y si creo un link que diga CLIC para ir a ella inserto este codigo. index.php?id=otra y cumple su funcion.

Ahora llamo a una pagina que se llama producto.php y hago una consulta para que me muestre los datos basicos de la tabla como nombre y valor y creo un link que se llama Detalles , pero al hacer clic en este enlace me da, debido a que la configuracion $_GET[id] no me la reconoce, pues no esta entre sus parametros, COMO HAGO PARA QUE ESTO ME FUNCIONE, COMO HAGO PARA QUE UNA WEB MODULAR ME ACEPTE ESTOS PROCEDIMIENTOS?.

producto.php

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

mysql_select_db($database_conexion$conexion);
$query_producto "SELECT * FROM productos";
$producto mysql_query($query_producto$conexion) or die(mysql_error());
$row_producto mysql_fetch_assoc($producto);
$totalRows_producto mysql_num_rows($producto);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<table width="513">
  <tr>
    <td><?php echo $row_producto['nombre']; ?></td>
  </tr>
  <tr>
    <td><?php echo $row_producto['valor']; ?></td>
  </tr>
</table>
<p><a href="index.php?id=detalles.php?id=<?php echo$row_producto[id];?>">Detalles</a></p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($producto);
?>
detalles.php

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

$colname_detalles "-1";
if (isset(
$_GET['id'])) {
  
$colname_detalles $_GET['id'];
}
mysql_select_db($database_conexion$conexion);
$query_detalles sprintf("SELECT * FROM productos WHERE id = %s"GetSQLValueString($colname_detalles"int"));
$detalles mysql_query($query_detalles$conexion) or die(mysql_error());
$row_detalles mysql_fetch_assoc($detalles);
$totalRows_detalles mysql_num_rows($detalles);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<table>
  <tr>
    <td width="477"><?php echo $row_detalles['nombre']; ?></td>
  </tr>
  <tr>
    <td><?php echo $row_detalles['descripcion']; ?></td>
  </tr>
  <tr>
    <td><?php echo $row_detalles['valor']; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result
($detalles);
?>
y este es el resultado que me da cuando voy a detalles en la barra de direcciones:

http://localhost:8082/modu/index.php?id=detalles.php?id=1
  #2 (permalink)  
Antiguo 23/10/2007, 23:40
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Exclamación Me hago entender

La web modular me funciona bien, el problema radica cuando en la pagina productos hago un link por medio de parametros url a la pagina detalles, la cual me va a dar esta direccion en la barra del explorer: http://localhost:8082/modu/index.php?id=detalles.php?id=1 por consiguiente no se me reconoce la pagina y me muestra erro o que no existe.


Como hago para solucionar esto?.





Muchas Gracias.
  #3 (permalink)  
Antiguo 24/10/2007, 03:16
 
Fecha de Ingreso: octubre-2004
Mensajes: 2.627
Antigüedad: 19 años, 5 meses
Puntos: 48
Re: Como funciona esto

Solo un ?, para separar entre parametros usa &. Te sobra el .php del id. No puedes tener dos parametros con el mismo nombre (si puedes, pero te dara dolores de cabeza), asi que cambia uno a otro nombre. El link te tiene que quedar http://localhost:8082/modu/index.php...=detalles&id=1
  #4 (permalink)  
Antiguo 24/10/2007, 10:34
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Re: Como funciona esto

Hola DarkJ disculpa la ignorancia, pero lo he hecho y no me da,

tengo que hacerlo aqui?.


Código PHP:

<?php 
if($_GET[id] == "") { 
    include(
"modulos/inicio.php");  
} else { 
    if(
file_exists("modulos/".$_GET[id].".php")) { 
        include(
"modulos/".$_GET[id].".php"); 
    } else { 
        include(
"modulos/error.php"); 
    } 

?>

Otra cosa, como ves el la pagina de productos, pasa el parametro por url a detalles por medio de id, con lo que me dices esto funcionara?, quede sin entender.

Gracias.
  #5 (permalink)  
Antiguo 24/10/2007, 10:41
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Pregunta Tampoco asi

Hola de nuevo lo he hecho en la pagina de productos:

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

mysql_select_db($database_conexion$conexion);
$query_producto "SELECT * FROM productos";
$producto mysql_query($query_producto$conexion) or die(mysql_error());
$row_producto mysql_fetch_assoc($producto);
$totalRows_producto mysql_num_rows($producto);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<table width="513">
  <tr>
    <td><?php echo $row_producto['nombre']; ?></td>
  </tr>
  <tr>
    <td><?php echo $row_producto['valor']; ?></td>
  </tr>
</table>
<p><a href="index.php?id=detalles&amp;id=<?php echo$row_producto[id];?>">Detalles</a></p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($producto);
?>

al dar clic en en lik me abre la ventana y aparece error. en el browser se ve esto:

http://localhost:8082/modu/index.php?id=detalles&id=1

pero el contenido no me carga

y me vota el erro predefinido : ERROR LA PAGINA NO EXISTE .



Me esta volviendo loco esto.


Gracias
  #6 (permalink)  
Antiguo 24/10/2007, 16:42
 
Fecha de Ingreso: octubre-2004
Mensajes: 2.627
Antigüedad: 19 años, 5 meses
Puntos: 48
Re: Como funciona esto

Porque has llamado a los 2 parametros igual id, por lo que php le asigna el ultimo valor , el 1 e intenta abrir 1.php

Cambia el nombre a uno de los 2.
  #7 (permalink)  
Antiguo 24/10/2007, 18:17
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
No se me soluciona

No encuentro solucion en lo que me dicen, si me dan una explicacion mas terrenal les agradezco, por que no veo por donde.

Gracias
  #8 (permalink)  
Antiguo 24/10/2007, 20:02
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Re: Como funciona esto

a lo que se refiere que el link tiene que ser algo así:
http://localhost:8082/modu/index.php...otravariable=1

no tenes que repetir las variables del parámetro id, porque sino el php no sabe cual usar
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 01:05.