Ver Mensaje Individual
  #7 (permalink)  
Antiguo 18/10/2013, 11:48
andresgerard
 
Fecha de Ingreso: octubre-2013
Ubicación: Maracaibo
Mensajes: 10
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: Se Borran los Campos en formularios de Registros al validarlos

Cuando entro al formulario "RegistarUsuarios.php" me aparecen estos mensajes en los campos:

<br /><b>Notice</b>: Undefined index: nombre in <b>C:\xampp\htdocs\prueba1\RegistarUsuarios.php</b> on line <b>62</b><br />

por lo que veo la variable no esta iniciada, le doy submit al formulario y queda la pantalla en blanco

El codigo me quedo asi:

RegistarUsuarios.php

Código PHP:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
@session_start(); //@ previene warning contra sesiones automáticas (no recomendado)

if(!isset($_SESSION["user"]))
{
    
$mensaje='No ha iniciado sesión, por favor verifica los datos o contacta al administrador.';
    print 
"<script>alert('$mensaje')</script>";
    print(
"<script>window.location.replace('index.php');</script>");
    exit;
}
if ((
$_SESSION['privilege'])=='yes')
{
?>

<!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>
<style type="text/css">
    body 
    {
        font-family: Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;
        color: black;
        background-color: #FFFFFF
    }

    .contenedor {position:relative;     width:1024px; height:768px; margin:0px auto; text-align:center;}
    .cuerpo {width:1024px; height:300px; text-align:center;}
    
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registrar Usuarios</title>
</head>
<div class="contenedor">

<body align="center" style='background-repeat:no-repeat; background-position: 50% 0%;' background="/prueba1/images/fondo.png">
</br></br></br></br></br></br></br></br></br></br></br>
<h2>Registro de Usuarios</h2>
<h3>Ingrese los datos del Usuario a Registrar</h3>
<div class="cuerpo">
<form action="registroUsuarios.php" method="post">
  
  <table align="center">
    <tr>
      <td align="left">Usuario:</td>
      <td align="center"><input type="text" value="<?php $_SESSION['form']['user'?>" name="user" size="25" /></td>
    </tr>
    <tr>
      <td align="left">Contraseña:</td>
      <td align="center"><input type="password" size="25" name="password" /></td>
    </tr>
    <tr>
      <td align="left">Es Administrador?:</td>
      <td align="center">
                        <SELECT style="width:176px; align:center;" align="center" NAME="esadmin">
                            <OPTION value="SI">SI</OPTION>
                            <OPTION value="NO" SELECTED>NO</OPTION>
                        </SELECT></td>
    </tr>
    <tr>
      <td align="left">Nombre:</td>
      <td align="center"><input type="text" size="25" value="<?php $_SESSION['form']['nombre'?>" name="Nombre"/></td>
    </tr>
     <tr>
      <td align="left">Apellido:</td>
      <td align="center"><input type="text" size="25"  value="<?php $_SESSION['form']['apellido'?>" name="Apellido"/></td>
    </tr>
    <tr>
      <td align="left">Cedula:</td>
      <td align="center" valign="middle"><input type="text" size="1" name="vzlano" value="V-" disabled=true/><input type="text" size="20" value="<?php $_SESSION['form']['cedula'?>" name="Cedula"/></td>
    </tr>
    <tr>
      <td align="left">Teléfono:</td>
      <td align="center"><input type="text" size="25" value="<?php $_SESSION['form']['telefono'?>" name="Telefono"/></td>
    </tr>
  </table>


</br>
<button name="submit" type="submit" title="Submit" >
<img src="/prueba1/images/Ok.png" width="64" height="64" border="0"></br>Enviar 
</button>****
<button name="atras" type="reset" title="Borrar" >
<img src="/prueba1/images/trash.png" width="64" height="64" border="0"></br>Borrar 
</button>****
<button name="atras" onclick=" location.href='PanelUsuarios.php' " type="button" title="Atras" >
<img src="/prueba1/images/atras.png" width="64" height="64" border="0"></br>Atrás 
</button>
</div></div>
</form>
</body>
</html>
<?php
}
else
{
    
$mensaje99='No tienes los privilegios suficientes para acceder a esta Página, por favor Contacta al Administrador .';
    print 
"<script>alert('$mensaje99')</script>";
    print(
"<script>window.location.replace('index.php');</script>");
    exit;
}
y el registroUsuario.php

Código PHP:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
@session_start(); //@ previene warning contra sesiones automáticas (no recomendado)
if(!isset($_SESSION["user"]))
{
    
$mensaje='No haz iniciado sesion, por favor verifica los datos o contacta al administrador.';
    print 
"<script>alert('$mensaje')</script>";
    print(
"<script>window.location.replace('index.php');</script>");
    exit;
}

if ((
$_SESSION['privilege'])=='yes')
{

require_once(
'funciones.php');
conectar('localhost','root','','gammu');
//Recibir

$user strip_tags($_POST['user']);
$password strip_tags(sha1($_POST['password']));
$esadmin strip_tags($_POST['esadmin']);
$Nombre strip_tags($_POST['Nombre']);
$Apellido strip_tags($_POST['Apellido']);
$Cedula strip_tags($_POST['Cedula']);
$Telefono strip_tags($_POST['Telefono']);

$user=trim($user);
$password=trim($password);
$esadmin=trim($esadmin);
$Nombre=trim($Nombre);
$Apellido=trim($Apellido);
$Cedula=trim($Cedula);
$Telefono=trim($Telefono);

$error==false;

if ((
$user)==NULL || ($user)==' ')

    
$error==true;
    
$mensaje='Disculpe, el Campo Usuario no puede estar en Blanco, Por favor Vuelva a intentarlo.';
}
else if ((
$password)==NULL || ($password)==' ')
{
    
$error==true;
    
$mensaje='Disculpe, el Campo Contraseña no puede estar en Blanco, Por favor Vuelva a intentarlo.';
}
else if ((
$Nombre)==NULL || ($Nombre)==' ')
{
    
$error==true;
    
$mensaje='Disculpe, el Campo Nombre no puede estar en Blanco, Por favor Vuelva a intentarlo.';
}
else if ((
$Apellido)==NULL || ($Apellido)==' ')
{
    
$error==true;
    
$mensaje='Disculpe, el Campo Apellido no puede estar en Blanco, Por favor Vuelva a intentarlo.';
}
else if ((
$Cedula)==NULL || is_numeric($Cedula)==FALSE)
{
    
$error==true;
    
$mensaje='Disculpe, el Campo Cedula no puede estar en Blanco y/o tener caracteres especiales, Recuerde utilizar solo Números, Por favor Vuelva a intentarlo.';
}
else if ((
$Telefono)==NULL || is_numeric($Telefono)==FALSE)
{
    
$error==true;
    
$mensaje='Disculpe, el Campo Teléfono no puede estar en Blanco y/o tener caracteres especiales, Recuerde utilizar solo Números, Por favor Vuelva a intentarlo.';
} else if (
$error == true)
{
    
$_SESSION['form']['user'] = $user;
    
$_SESSION['form']['nombre'] = $Nombre;
    
$_SESSION['form']['apellido'] = $Apellido;
    
$_SESSION['form']['cedula'] = $Cedula;
    
$_SESSION['form']['telefono'] = $Telefono;
    print 
"<script>alert('$mensaje')</script>";
    print(
"<script>window.location.replace('RegistarUsuarios.php');</script>");     
}
else
{

$query = @mysql_query('SELECT * FROM usuarios WHERE user="'.mysql_real_escape_string($user).'"');

if(
$existe = @mysql_fetch_object($query))
{
    echo 
'El Usuario '.$user.' ya Existe.';
}else{
    
$meter = @mysql_query('INSERT INTO usuarios (user, password, ADMIN, Nombre, Apellido, Cedula, Telefono) values("'.mysql_real_escape_string($user).'","'.mysql_real_escape_string($password).'","'.mysql_real_escape_string($esadmin).'","'.mysql_real_escape_string($Nombre).'","'.mysql_real_escape_string($Apellido).'","'.mysql_real_escape_string($Cedula).'","'.mysql_real_escape_string($Telefono).'")');
    if(
$meter)
    {
        
$mensaje6='Usuario Registrado con Éxito';
        print 
"<script>alert('$mensaje6')</script>";
        print(
"<script>window.location.replace('/RegistarUsuarios.php');</script>");
    }
        else
        {
            
$mensaje7='Hubo un problema Registrando el Usuario, por favor vuelva a intentarlo';
            print 
"<script>alert('$mensaje7')</script>";
            print(
"<script>window.location.replace('/RegistarUsuarios.php');</script>");
        }
}

}

}
else
{
    
$mensaje99='No tienes los privilegios suficientes para acceder a esta Página, por favor Contacta al Administrador .';
    print 
"<script>alert('$mensaje99')</script>";
    print(
"<script>window.location.replace('index.php');</script>");
    
session_destroy(); 
    exit;
}
?>