Una vez pulsamos sobre el botón editar se me va a este codigo php.
Código PHP:
<?php
function renderForm($id, $IP, $NOMBRE, $DESC, $TIPO, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Editar entrada</title>
<style type="text/css">
.Titulo {
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
t-weight: bold;
font-weight: bold;
color: #000;
}
.Titulo2 {
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
color: #000;
}
</style>
</head>
<body>
<?php
// Mostrar solo si existen errores
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div>
<span class="Titulo"><br>Dirección IP:
</span><span class="Titulo2">
<?php echo $IP; ?><br/>
<span class="Titulo"><br>Hostname:
</span><span class="Titulo2">
<input type="text" name="NOMBRE" value="
<?php echo $NOMBRE; ?>"/><br/>
<span class="Titulo"><br>Tipo:
</span><span class="Titulo2">
<select name="listado" id="listado">
<?php
echo "<option value='gateway'" ;
if ($TIPO == "gateway") echo "selected='selected'" ;
echo ">Gateway (puerta de enlace, HSRP)</option>" ;
echo "<option value='router'" ;
if ($TIPO == "router") echo "selected='selected'" ;
echo ">Router</option>" ;
echo "<option value='switch'" ;
if ($TIPO == "switch") echo "selected='selected'" ;
echo ">Switch</option>" ;
echo "<option value='server'" ;
if ($TIPO == "server") echo "selected='selected'" ;
echo ">Servidor</option> ";
echo "<option value='dhcp'" ;
if ($TIPO == "dhcp") echo "selected='selected'" ;
echo ">DHCP</option>" ;
echo "<option value='apw'" ;
if ($TIPO == "apw") echo "selected='selected'" ;
echo ">Punto de acceso inalámbrico</option>" ;
echo "<option value='printer'" ;
if ($TIPO == "printer") echo "selected='selected'" ;
echo ">Impresora</option>" ;
echo "<option value='nas'";
if ($TIPO == "nas") echo "selected='selected'" ;
echo ">NAS o Cabina de disco</option>" ;
echo "<option value='other'" ;
if ($TIPO == "other") echo "selected='selected'" ;
echo ">Otro</option>" ;
echo "<option value='temp'" ;
if ($TIPO == "temp") echo "selected='selected'" ;
echo ">Temporal</option>";
echo "<option value='free'" ;
if ($TIPO == "free") echo "selected='selected'" ;
echo ">Libre</option>" ;
?>
</select> <br/>
</span>
<span class="Titulo"><br>Descripción:
</span><span class="Titulo2">
<input type="text" name="DESC" value="
<?php echo $DESC; ?>"/>
<br><br>
<input type="submit" name="submit" value="Guardar datos">
</div>
</form>
</body>
</html>
<?php
}
// connect to the database
include('connect-db.php');
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['id']))
{
// get form data, making sure it is valid
$id = $_POST['id'];
$NOMBRE = mysql_real_escape_string(htmlspecialchars($_POST['NOMBRE']));
$DESC = mysql_real_escape_string(htmlspecialchars($_POST['DESC']));
$TIPO = mysql_real_escape_string(htmlspecialchars($_POST['TIPO']));
// check that NOMBRE/DESC fields are both filled in
if ($NOMBRE == '' || $DESC == '' || $TIPO == '')
{
// Genera un mensaje de error
$error = 'ERROR: Por favor, rellene los campos obligatorios!';
// Muestra los campos de nuevo
renderForm($id, $NOMBRE, $DESC, $TIPO, $error);
}
else
{
// Guardar los datos dentro de la base de datos
mysql_query("UPDATE " . $_GET['varsede'] . " SET " . $_GET['varsede'] . ".`NOMBRE`='$NOMBRE', " . $_GET['varsede'] . ".`DESC`='$DESC' , " . $_GET['varsede'] . ".`TIPO`='$TIPO' WHERE IDENTIFICADOR='$id'") or die(mysql_error());
// mysql_query("UPDATE " . $_GET['varsede'] . " SET NOMBRE='$NOMBRE', DESC='$DESC' WHERE IDENTIFICADOR='$id'")
// Una vez guardada la infiormación, vuelve a la página inicial
header("Location: ok.html");
//header("Location: enviar.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error!';
}
}
else
{
// if the form hasn't been submitted, get the data from the db and display the form
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
$varsede = $_GET['varsede'];
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
// query db
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM " . $_GET['varsede'] . " WHERE IDENTIFICADOR=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$IP = $row['IP'];
$NOMBRE = $row['NOMBRE'];
$DESC = $row['DESC'];
$TIPO = $row['TIPO'];
// show form
renderForm($id, $IP, $NOMBRE, $DESC, $TIPO, '');
}
else
{
// if no match, display result
echo "No results!";
}
}
else
{
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
echo 'Error!';
}
}
Notice: Undefined index: TIPO in /opt/lampp/htdocs/server/GestionIp/edit.php on line 138
Warning: Missing argument 6 for renderForm(), called in /opt/lampp/htdocs/server/GestionIp/edit.php on line 147 and defined in /opt/lampp/htdocs/server/GestionIp/edit.php on line 4
Notice: Undefined variable: error in /opt/lampp/htdocs/server/GestionIp/edit.php on line 34
No entiendo que pasa la verdad y pero bueno a ver si me pueden ayudar por aquí . Otra cosa en los botones que he comentado antes lo suyo seria que saltaran en pop up así siempre veríamos la pagina principal. y a su vez cuando pulsamos enviar no me vuelve a la pagina donde muestro los datos , me lleva a una pagina de inicio que le hemos puesto ya que si le digo que vaya a la pagian donde están los datos peta porque entiendo que el valor de las variables ya se ha borrado. Estoy hecho un lío...