Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/10/2008, 18:12
hinfra
 
Fecha de Ingreso: octubre-2008
Mensajes: 93
Antigüedad: 15 años, 7 meses
Puntos: 1
Problema al crear un pequeño sistema php/mysql

Saludos, estoy creando un pequeño sistema para introducir datos sobre coches en una BD, toda me funciona perfectamente siguiendo el código de un libro, pero tengo problemas con el identificador (id) que utiliza para modificar los registros o para ver las fichas de los coches individualmente.

No sé que ocurre pero todo funciona perfectamente, pero no hace lo que tendria que hacer... Introduce los registros perfectamente, pero no modifica ni muestra las paginas individuales de cada registro.

Yo creo, como decía, que se debe a algun problema con la variable $id que utilizo para modificar y mostrar los links, pero la verdad es que no identifico el origen.

Perdonarme por la extensión, estaré eternamente agradecido.

El código es este:

forminserta.php

Código PHP:
<?php

include ("header.php");
include (
"conectar.php");

?>

<form name="form" action="insertacoches.php" method="post">

<h5>Seleccione la marca de su vehiculo:
<select name="marca">
<option value="alfaromeo">Alfa Romeo</option>
<option value="audi">Audi</option>
<option value="bmw">BMW</option>
</select>

<br/>
</h5>
<h5>
Indique el modelo:
<input name="modelo" type="text" size="45" />
</h5>
<h5>
Indique el color:
<input name="color" type="text" size="48" />
</h5>
Combustible:
<input name="combustible" type="radio" value="diesel" checked="checked" />Diesel
<input name="combustible" type="radio" value="gasolina" />Gasolina
</h5>
<h5>
Año matriculacion:
<input name="fecha" type="text" size="10" />
</h5>
<h5>
Precio:
<input type="text" name="precio" size="10" />
</h5>
<h5>
<input name="Enviar" type="submit" value="Enviar" />
</h5>
</form>

<?php

include ("footer.php");

?>
insertacoches.php

Código PHP:
<?php

include ("header.php");
include (
"conectar.php");


//Por si el servidor tiene desactivados los register globals----
$marca=$_POST['marca'];
$modelo=$_POST['modelo'];
$combustible=$_POST['combustible'];
$color=$_POST['color'];
$fecha=$_POST['fecha'];
$precio=$_POST['precio'];
//--------------------------------------------------------------


$db="musicdai";
mysql_select_db($db,$conectar);

$result mysql_query("insert into ocasion (marca, modelo, combustible, color, fecha, precio) values ('$marca', '$modelo', '$combustible', '$color', '$fecha', '$precio')"$conectar);

echo 
"A insertado los siguientes datos:";
echo 
"<br /><br />";
echo 
"Marca:$marca";
echo 
"<br />";
echo 
"Modelo:$modelo";
echo 
"<br />";
echo 
"Combustible:$combustible";
echo 
"<br />";
echo 
"Color:$color";
echo 
"<br />";
echo 
"Fecha:$fecha";
echo 
"<br />";
echo 
"Precio:$precio";
echo 
"<br /><br />";
?>

<a href="forminserta.php">Volver a introducir un nuevo coche</a>

<?php

include ("footer.php");

?>

buscador.php

Código PHP:
<?php

include ("header.php");
include (
"conectar.php");
?>

<form name="form" action="buscacoches.php" method="post">

Seleccione la marca de su vehiculo:
<select name="marca">
<option value="alfaromeo">Alfa Romeo</option>
<option value="audi">Audi</option>
<option value="bmw">BMW</option>
</select>

<br />

Indique el modelo:<br />
<input name="modelo" type="text" size="45" />
Año matriculacion:
<input name="fecha" type="text" size="10" />
Precio:
<input name="precio" type="text" size="10" />
<input name="Enviar" type="submit" value="Enviar" />
</form>

<?php

include ("footer.php");

?>
buscacoches.php

Código PHP:
<?php

include ("header.php");
include (
"conectar.php");

//Por si el servidor tiene desactivados los register globals----
$marca=$_POST['marca'];
$modelo=$_POST['modelo'];
$fecha=$_POST['fecha'];
$precio=$_POST['precio'];
//$id=$_POST['id'];
$id $_GET['id'];
//--------------------------------------------------------------

$db="musicdai";
mysql_select_db($db,$conectar);

$consultamysql_query("select * from ocasion where marca like '$marca' or modelo like '$modelo' or fecha like '$fecha' or precio like '$precio'"$conectar);

while (
$row mysql_fetch_array($consulta)) {
$id$row["id"];
$marca$row["marca"];
$modelo$row["modelo"];
$fecha$row["fecha"];

echo (
"<table width='100%' border='0' cellspacing='0' cellpadding='0'>\n");
echo (
"<tr>\n");
echo(
"<td width='12%'><a href=modificarcoche.php?id=$id>Modificar</a></td>\n");
echo(
"<td width='12%'><a href=borrarcoches.php?id=$id>Borrar</a></td>\n");
echo (
"<td width='26%'><a href=coches.php?id=$id>$marca</a></td>\n");
echo (
"<td width='26%'>$modelo</a></td>\n");
echo (
"<td width='24%'>$fecha</a></td>\n");
echo (
"</table>\n");
}
?>

<a href="buscador.php">Volver a buscar</a>

<?php

include ("footer.php");

?>

modificarcoche.php

Código PHP:
<?php

include ("header.php");
include (
"conectar.php");
?>

<form name="form" action="modificarcoche2.php" method="post">
Seleccione la marca de su vehiculo:
<select name="marca">
<option value="alfaromeo">Alfa Romeo</option>
<option value="audi">Audi</option>
<option value="bmw">BMW</option>
</select>

<br/>
</h5>
<h5>
Indique el modelo:
<input name="modelo" type="text" size="45" />
</h5>
<h5>
Indique el color:
<input name="color" type="text" size="48" />
</h5>
Combustible:
<input name="combustible" type="radio" value="diesel" checked="checked" />Diesel
<input name="combustible" type="radio" value="gasolina" />Gasolina
</h5>
<h5>
Año matriculacion:
<input name="fecha" type="text" size="10" />
</h5>
<h5>
Precio:
<input type="text" name="precio" size="10" />
</h5>
<h5>
<input type="hidden" name="id" value="<?=$id?>">
<input name="Enviar" type="submit" value="Enviar" />
</h5>
</form>

<?php
include ("footer.php");
?>

modificarcoche2.php

Código PHP:
<?php

include ("header.php");
include (
"conectar.php");

$db="musicdai";
mysql_select_db($db,$conectar);

//Por si el servidor tiene desactivados los register globals----
$marca=$_POST['marca'];
$modelo=$_POST['modelo'];
$combustible=$_POST['combustible'];
$color=$_POST['color'];
$fecha=$_POST['fecha'];
$precio=$_POST['precio'];
//$id=$_POST['id'];
$id $_GET['id'];
//--------------------------------------------------------------

$result mysql_query("update ocasion set marca='$marca', modelo='$modelo', combustible='$combustible', color='$color', fecha='$fecha', precio='$precio' where id='$id'"$conectar);

echo 
"Actualizando los siguientes datos";
echo 
"<br /><br />";
echo 
"Marca: $marca";
echo 
"<br />";
echo 
"Modelo: $modelo";
echo 
"<br />";
echo 
"Combustible: $combustible";
echo 
"<br />";
echo 
"Color: $color";
echo 
"<br />";
echo 
"Fecha: $fecha";
echo 
"<br />";
echo 
"Precio: $precio";
echo 
"<br /><br />";
echo 
"id: $id";
?>

<a href="buscador.php">Volver a buscar</a>

<?php
include ("footer.php");
?>
coches.php

Código PHP:
<?php

include ("header.php");
include (
"conectar.php");
?>

<form name="form" action="buscachoches.php" method="post">

<?php
$db
="musicdai";
mysql_select_db($db,$conectar);

//Por si el servidor tiene desactivados los register globals----
$marca=$_POST['marca'];
$modelo=$_POST['modelo'];
$combustible=$_POST['combustible'];
$color=$_POST['color'];
$fecha=$_POST['fecha'];
$precio=$_POST['precio'];
//$id=$_POST['id'];
$id $_GET['id'];
//--------------------------------------------------------------


$consulta mysql_query("select * from ocasion where id=$id"$conectar);

while(
$row mysql_fetch_array($consulta))
{
$id$row["id"];
$marca$row["marca"];
$modelo$row["modelo"];
$fecha$row["fecha"];
$color$row["color"];
$combustible$row["combustible"];
$precio$row["precio"];

echo 
"Los datos del vehiculo que ha solicitado son los siguientes:";
echo 
"<br />";
echo 
"Marca:$marca";
echo 
"<br />";
echo 
"Modelo:$modelo";
echo 
"<br />";
echo 
"Combustible:$combustible";
echo 
"<br />";
echo 
"Color:$color";
echo 
"<br />";
echo 
"Fecha:$fecha";
echo 
"<br />";
echo 
"Precio:$precio";
}

?>

<a href="buscador.php">Volver a buscar</a>

<?php

include ("footer.php");

?>

Última edición por hinfra; 16/10/2008 a las 18:37