Tema: Errores PHP
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/04/2012, 01:52
cromero2416
 
Fecha de Ingreso: abril-2012
Mensajes: 28
Antigüedad: 12 años
Puntos: 0
Errores PHP

Buenos días amigos tengo un problemita con un código PHP que me esta trayendo por la calle de la amargura jajaja os pongo en situación , estoy haciendo una gestión de ips con php y mysql entonces yo muestro por pantalla la tabla del mysql y en la parte de la izquierda de la pantalla hay un tres iconos , uno es el de editar otro de hacer un ping y el otro de vaciar ciertos campos , así a muy groso modo.

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&oacute;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&oacute;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!';
        }
    }
Este editar te saca un pequeño formulario donde muestra el id , el nombre una descripción y una lista desplegadle que lo que muestra es lo que es la ip ósea un router , switch entre otras pues bueno una vez hemos rellenado los campos y pulsamos a enviar me saltan todos estos errores.

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...