Formulario de Registro en PHP

Nombre de Archivo: registro.php




<?PHP 
//realizar la conexion desde otro archivo
include(‘/controlador.php’);



//recibir el boton
$boton=$_POST[“boton”];


//recibir los datos del formulario
$cedula = $_POST[‘cedula’];
$nombre = $_POST[‘nombre’];
$carrera = $_POST[‘carrera’];




// condicion para Almacenar los datos
if($boton==”Guardar”){
$sql=”insert into practica( cedula, nombre, carrera) 
values(‘$cedula’, ‘$nombre’, ‘$carrera’)”;
if(mysql_query($sql)){
echo “<script>alert(‘Datos GUARDADOS Correctamente’)</script>”;
echo “<script>window.location=’registro.php'</script>”;
}else{
echo “<script>alert(‘Datos no pudieron ser GUARDADOS’)</script>”;
}

}


// condicion para Buscar los datos
if($boton==”Buscar”){
$sql=”select * from practica where cedula=’$cedula’ “;
$busqueda=mysql_query($sql);
if($registro=mysql_fetch_array($busqueda)){
$campo_clave = $registro[‘campo_clave’];
$cedula = $registro[‘cedula’];
$nombre = $registro[‘nombre’];
$carrera = $registro[‘carrera’];


}else{
echo “<script>alert(‘Registro NO EXISTE en el Sistema’)</script>”;
}

}


// condicion para Eliminar los datos
if($boton==”Eliminar”){
if($cedula!=””){
$sql=”delete from practica where cedula=’$cedula'”;
mysql_query($sql);
echo “<script>alert(‘Datos ELIMINADOS Correctamente’)</script>”;
echo “<script>window.location=’registro.php'</script>”;
}else{
echo “<script>alert(‘Para poder ELIMINAR debe Realizar una busqueda’)</script>”;
echo “<script>window.location=’registro.php'</script>”;
}

}


// condicion para Modificar los datos
if($boton==”Modificar”){
if($cedula!=””){
$sql=”update practica set cedula=’$cedula’, nombre=’$nombre’, carrera=’$carrera’ where cedula=’$cedula'”;
mysql_query($sql);
echo “<script>alert(‘Datos Modificados Correctamente’)</script>”;
echo “<script>window.location=’registro.php'</script>”;
}else{
echo “<script>alert(‘Para poder Modificadar debe Realizar una busqueda’)</script>”;
echo “<script>window.location=’registro.php'</script>”;
}

}






?>
<!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>Sistema Basico</title>
<style type=”text/css”>
<!–
.Estilo1 {
font-size: 18px;
font-weight: bold;
}
–>
</style>
</head>
<body>
<div align=”center”><img src=”1.jpg” />
</div>
<form action=”” method=”post” name=”form1″>
<table width=”50%” border=”0″ align=”center” cellpadding=”7″ cellspacing=”0″>
  <tr>
    <td colspan=”2″><div align=”center” class=”Estilo1″> Registro de Alumnos </div></td>
    </tr>
  <tr>
    <td><div align=”right”>Cedula:</div></td>
    <td><input name=”cedula” type=”text” size=”25″ maxlength=”30″ value=”<?PHP echo $cedula; ?>” /></td>
  </tr>
  <tr>
  <tr>
    <td><div align=”right”>Nombre:</div></td>
    <td><input name=”nombre” type=”text” size=”40″ maxlength=”30″ value=”<?PHP echo $nombre; ?>” /></td>
  </tr>
  <tr>
    <td><div align=”right”>Carrera:</div></td>
    <td><select name=”carrera”>
 <option value=”I” <?PHP if($carrera==’I’){ echo ‘selected=”selected”‘; } ?> >Seleccione una Carrera</option>
      <option value=”I” <?PHP if($carrera==’I’){ echo ‘selected=”selected”‘; } ?> >Informatica</option>
      <option value=”A” <?PHP if($carrera==’A’){ echo ‘selected=”selected”‘; } ?> >Administracion</option>
      <option value=”T” <?PHP if($carrera==’T’){ echo ‘selected=”selected”‘; } ?> >Turismo</option>
      <option value=”H” <?PHP if($carrera==’H’){ echo ‘selected=”selected”‘; } ?> >Hoteleria</option>
    </select></td>
  </tr>
  
  <tr>
    <td colspan=”2″><div align=”center”>
      <table width=”80%” border=”0″ cellpadding=”5″ cellspacing=”0″>
        <tr>
          <td><div align=”center”>
            <label>
            <input type=”submit” name=”boton” value=”Guardar” />
            </label>
          </div></td>
          <td><div align=”center”>
            <input type=”submit” name=”boton” value=”Buscar” />
          </div></td>
          <td><div align=”center”>
            <input type=”submit” name=”boton” value=”Eliminar” />
          </div></td>
          <td><div align=”center”>
            <input type=”submit” name=”boton” value=”Modificar” />
          </div></td>
  <td><div align=”center”>
            <input type=”reset” name=”boton” value=”Limpiar” />
          </div></td>
        </tr>
      </table>
    </div></td>
    </tr>
</table>
</form>
</body>

</html>