Buenas a todos!!
Estoy empezando con esto de PHP, bases de datos y estoy haciendo como una especie de Web para una empresa de taxis.
Me da un Warning como si no se enviara un $_POST y no encuentro la solución.
Os dejo el código por si podéis orientar un poco.
<!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=iso-8859-1" />
<title>Modificar Datos</title>
<link rel="stylesheet" href="tabla.css" />
</head>
<body>
<h1>Selecciona la Matrícula para modificar los datos</h1>
<?php$conexion = mysqli_connect("localhost:3306", "root", "", "taxicorp");if (!isset($_POST["Matricula"])) {echo ("<form action='cambio.php' method='post'>");$sel = "SELECT Matricula FROM taxis";$exec = mysqli_query($conexion, $sel);$row = mysqli_fetch_array($exec);echo ('<select name="Matricula" id="Matricula">');while ($registro = mysqli_fetch_array($exec)) {echo ('<option>' . $registro["Matricula"] . "</option>");}?>
</select>
<input type="submit" id="cambia" name="cambia" value="enviar" />
<?php} else {$sel = "SELECT * FROM taxis WHERE Matricula='" . $_POST["Matricula"] . "'";$exec = mysqli_query($conexion, $sel);if (!$exec) echo("Error al conectar con la base" . mysqli_error($conexion));$row = @mysqli_fetch_array($exec); echo("<form action='cambia2.php' method='post'>");?>
<table border="1">
<tr><th colspan="2">Matrícula: <font color="red"><strong><?php echo($_POST["Matricula"]); ?>
</strong></font></th></tr>
<tr>
<td>Modelo:</td>
<td colspan="1"><input type="text" name="Modelo" required value='<?php echo($row["Modelo"]); ?>
' /></td>
</tr>
<tr>
<td>Nombre:</td>
<td colspan="1">
<input name="Nombre" type="text" id="Nombre" size="20" required maxlength="20" value='<?php echo($row["Nombre"]); ?>
'/></td></tr>
<tr><td>Apellidos:</td><td><input name="Apellidos" type="text" id="Apellidos" size="40" maxlength="40" required value='<?php echo($row["Apellidos"]); ?>
'/></td>
</TR>
<TR>
<td><font color="green">Libre:</font></td>
<td colspan="-1"><input name="libre" type="checkbox" id="libre" value="Libre" <?php if ($row["Ocupado"]) echo("checked"); ?>
/>
</td>
</TR>
<TR>
<td colspan="2" align="center"><input name="enviar" type="submit" id="enviar" value="Modificar Datos" /></td>
</TR>
</TABLE>
</form>
<?php}?>
</body>
</html>
Estos datos de arriba se envían a la siguiente página, que es donde me aparece el Warning.
<!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=iso-8859-1" />
<title>Cambia2</title>
<link rel="stylesheet" href="tabla.css" />
<style type="text/css">
a {
text-decoration:none;
color:#99CC66;
font-weight:600;
}
a:hover {
text-decoration: underline;
color:#99CC66;
font-weight:600;
}
</style>
</head>
<body>
<?php$conexion = mysqli_connect("localhost:3306", "root", "", "taxicorp");//Creamos la sentencia SQL y la ejecutamos$cambia="UPDATE taxis SET Modelo='" .$_POST["Modelo"] . "'," . "Nombre='" . $_POST["Nombre"] . "',"; $cambia.="Apellidos='" . $_POST["Apellidos"] . "',Ocupado="; if (isset($_POST["Ocupado"])) $cambia.="true"; else $cambia.="false"; $cambia.=" WHERE Matricula='" . $_POST["Matricula"] . "'"; //Aquí me da el error$exec=mysqli_query($conexion, $cambia);if ($exec) echo("<H1>Cambio realizado</H1>");else echo("<H1>Se ha producido un error</H1>");?>
<div align="center"><a href="listado.php">Visualizar el contenido de la base</a></div>
</body>
</html>
Gracias de antemano, saludos.
Hola @César Krall, gracias por contestar.
Ya he resuelto el problema, he pasado los datos a través de $_COOKIE. Lo he dejado así, por si a alguien le interesa.
<?php@setcookie("Matricula",$_POST["Matricula"],time()+243600); //Aquí el cambio?>
<!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=iso-8859-1" />
<title>Modificar Datos</title>
<link rel="stylesheet" href="tabla.css" />
</head>
<body>
<h1>Selecciona la Matrícula para modificar los datos</h1>
<?php$conexion = mysqli_connect("localhost:3306", "root", "", "taxicorp");if (!isset($_POST["Matricula"])) {echo ("<form action='cambio.php' method='post'>");$sel = "SELECT Matricula FROM taxis";$exec = mysqli_query($conexion, $sel);$row = mysqli_fetch_array($exec);echo ('<select name="Matricula" id="Matricula">');while ($registro = mysqli_fetch_array($exec)) {echo ('<option>' . $registro["Matricula"] . "</option>");}?>
</select>
<input type="submit" id="cambia" name="cambia" value="enviar" />
<?php} else {$sel = "SELECT * FROM taxis WHERE Matricula='" . $_POST["Matricula"] . "'";$exec = mysqli_query($conexion, $sel);if (!$exec) echo("Error al conectar con la base" . mysqli_error($conexion));$row = mysqli_fetch_array($exec); //No lo entiendo!!//echo(mysql_result($row,0)); echo("<form action='cambia2.php' method='post'>");?>
<table border="1">
<tr><th colspan="2">Matrícula: <font color="red"><strong><?php if (isset($_POST["Matricula"])) echo($_POST["Matricula"]); ?>
</strong></font></th></tr>
<tr>
<td>Modelo:</td>
<td colspan="1"><input type="text" name="Modelo" required value='<?php echo($row["Modelo"]); ?>
' /></td>
</tr>
<tr>
<td>Nombre:</td>
<td colspan="1">
<input name="Nombre" type="text" id="Nombre" size="20" required maxlength="20" value='<?php echo($row["Nombre"]); ?>
'/></td></tr>
<tr><td>Apellidos:</td><td><input name="Apellidos" type="text" id="Apellidos" size="40" maxlength="40" required value='<?php echo($row["Apellidos"]); ?>
'/></td>
</TR>
<TR>
<td><font color="green">Libre:</font></td>
<td colspan="-1"><input name="libre" type="checkbox" id="libre" value="Libre" <?php if ($row["Ocupado"]) echo("checked"); ?>
/>
</td>
</TR>
<TR>
<td colspan="2" align="center"><input name="enviar" type="submit" id="enviar" value="Modificar Datos" /></td>
</TR>
</TABLE>
</form>
<?php}?>
</body>
</html>
Aquí recibe los datos...
<!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=iso-8859-1" />
<title>Cambia2</title>
<link rel="stylesheet" href="tabla.css" />
<style type="text/css">
a {
text-decoration:none;
color:#99CC66;
font-weight:600;
}
a:hover {
text-decoration: underline;
color:#99CC66;
font-weight:600;
}
</style>
</head>
<body>
<?php$conexion = mysqli_connect("localhost:3306", "root", "", "taxicorp");//Creamos la sentencia SQL y la ejecutamosecho "Dato recibido de modelo es ".$_POST["Modelo"];echo "Dato recibido de matricula es". $_POST["Matricula"];$sel="UPDATE taxis SET Modelo='" .$_POST["Modelo"] . "'," . "Nombre='" . $_POST["Nombre"] . "',"; $sel.="Apellidos='" . $_POST["Apellidos"] . "',Ocupado="; if (isset($_POST["libre"])) $sel.="false"; else $sel.="true"; $sel.=" WHERE Matricula='" . $_COOKIE["Matricula"] . "'"; //Aquí la recibe $exec=mysqli_query($conexion, $sel);if ($exec) echo("<H1>Cambio realizado</H1>");else echo("<H1>Se ha producido un error</H1>");?>
<div align="center"><a href="listado.php">Visualizar el contenido de la base</a></div>
</body>
</html>
Así me ha funcionado.
Gracias y saludos.