Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/05/2012, 00:02
Avatar de guillemat
guillemat
 
Fecha de Ingreso: abril-2012
Mensajes: 7
Antigüedad: 12 años
Puntos: 0
Registros de valor 0 en los campos clave

Hola amigos, tengo una situacion que me parece atipica, veamos si me pueden ayudar.

tengo este codigo que me inserta datos de un form php en dos tablas de mysql:

Código PHP:
<form method="post" name="form" id="form" action="inserta_admin.php">
  <
table align="center">
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Cedula:</td>
      <
td><input name="cedula" type="text"  required="required" size="12" maxlength="8" /></td>
    </
tr>
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Nombres:</td>
      <
td><input name="nombre" type="text" required size="32" maxlength="64" /></td>
    </
tr>
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Apellidos:</td>
      <
td><input name="apellido" type="text" required size="32" maxlength="64" /></td>
    </
tr>
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Password:</td>
      <
td><input name="password" type="password" required size="32" maxlength="15" /></td>
    </
tr>
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Reingrese su Password:</td>
      <
td><input name="password2" type="password" required size="32" maxlength="15" /></td>
    </
tr>
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Pregunta de seguridad:</td>
      <
td><input name="pregunta" type="text" required size="32" maxlength="128" /></td>
    </
tr>
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Respuesta de seguridad:</td>
      <
td><input name="respuesta" type="text" required size="32" maxlength="128" /></td>
    </
tr>
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Email:</td>
      <
td><input name="email" type="text" required size="32" maxlength="32" /></td>
    </
tr>
    
    <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Telefono celular:</td>
      <
td><input name="telcel" type="text" required size="32" maxlength="11" /></td>
      <
tr valign="baseline">
      </
tr>
      <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">Coordinación:</td>
      <
td align=""><select name="priv" id="priv" ><option value="0">Coordinación</option><option value="1">Administración</option>
      </
select></td>
      </
tr>
      <
tr valign="baseline">
      <
td nowrap="nowrap" align="right">&nbsp;</td>
      <
td><input type="submit" value="Inscribir" onClick="validarAdmin()" /></td>
    </
tr>
  </
table>
  <
input type="hidden" name="MM_insert" value="form" />
</
form
de ahi salta a esta pag:

Código PHP:
require_once('Include/clases.php');
//print_r($_POST);
$nom=$_POST['nombre']." ".$_POST['apellido'];
echo 
$nom;

$adm=new UsuAdmin($_POST['cedula'],$nom,$_POST['email']);
$adm->crearAdmin($_POST['cedula'],$nom,$_POST['pregunta'],$_POST['respuesta'],$_POST['email'],$_POST['telcel'],$_POST['password'],$_POST['priv']);
"<script type='text/javascript'>
window.location='entrada_administracion.php';
</script>"
;
?> 
y las clases involucradas son (archivo include/clases):

Código PHP:
class Conectar 
{
    protected 
$ident=array();

    
    public static function 
Conexion    () 
    {
        
$conexion=mysql_connect("localhost","root","");
        
mysql_query("SET NAMES 'utf8'");
        
mysql_select_db("asesorias",$conexion);
        return 
$conexion;
    }
}

class 
UsuAdmin extends Usuario
{
      protected 
$registro=array();
     
    public function 
__construct($cedula,$nombre$email
    {
        
parent::__construct($cedula,$nombre$email);
    }
    
     public function 
crearAdmin($cedula,$nombre,$pregunta,$respuesta$email,$telcel,$password,$priv
    {
        
$sql="insert into usu_admin values('$cedula','$nombre','$pregunta','$respuesta','$email','$telcel','$priv')";
        
$res=mysql_query($sqlConectar::Conexion()) or die(mysql_error());
        
$sql2="insert into usuario values('$cedula','$password','3','1')";
        
$res2=mysql_query($sql2Conectar::Conexion()) or die(mysql_error());
        echo 
"<script type='text/javascript'>
        alert('Usuario registrado correctamente');
        window.location='entrada_administracion.php';
        </script>"
;
    }  
    
    public function 
Buscausu($ced
    {
        
$sql="Select * from usu_admin as a join usuario as b on a.cedula=b.cedula where a.cedula='$ced'";
        
$res=mysql_query($sql,Conectar::Conexion())    or die(mysql_error());
        while(
$reg=mysql_fetch_assoc($res))
        {
            
$this->registro[]=$reg;    
        }
        return 
$this->registro;
    }
    
    public function 
modificaUsuario($ced,$nom,$pass,$pre,$resp,$ema,$tel,$priv,$act)
    {
        
$sql="Update usu_admin set cedula='$ced', nombre='$nom',pregunta='$pre',respuesta='$resp',email='$ema',telcel='$tel',privilegios='$priv' where cedula='$ced'";
        
$res=mysql_query($sqlConectar::Conexion()) or die(mysql_error());
        
$sql="Update usuario set cedula='$ced', password='$pass',activo='$act' where cedula='$ced'";
        
$res=mysql_query($sqlConectar::Conexion()) or die(mysql_error());

    }

En general, funcionan como debe (insertan datos) pero el problema es que si le dan hacia atras desde el navegador se crean registros con valores 0 y valores vacios.

Como puedo evitar esto????