jueves, 30 de enero de 2014

REGISTRO DE USUARIOS Y DAR PRIVILEGIOS



index.php
 <!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
        <script languaje='javascript'>
            function actualizar(n,v,x){
                location.href='index.php?pag=3&id='+n+'&v='+v+'&x='+x;
            }
    </script>
    </head>
    <body>
        <center>
            <h1>REGISTRO DE INFORMACIÓN</h1>
            <table width="100%" border="0px" cellpadding="0" cellspacing="0">
                <tr style="text-align: right;">
                    <td colspan=2><a href="index.php?pag=1">INICIO</a>|<a href="index.php?pag=5">CERRAR SESIÓN</a></td>
                </tr>
                <tr>
                    <td width="200px" style="vertical-align: top;  border: 1px solid #FF9900;">
                        <?php
                            include_once('registro.php');
                        ?>
                    </td>
                    <td height="500px" style="border-top: 1px solid #FF9900;vertical-align: top;">
                        <center>
                        <?php
                            if (isset($_GET['pag'])){
                            switch ($_GET['pag']) {
                                case 1:
                                    include_once('inicio.php');
                                    break;
                                case 2:
                                    include_once('usuarios.php');
                                    break;
                                case 3:
                                    include_once('admin.php');
                                    break;
                                case 4:
                                    include_once('user.php');
                                    break;
                                case 5;
                                    unset($_SESSION['user']);
                                    unset($_SESSION['nivel']);
                                    unset($_SESSION['activo']);
                                    echo "<script languaje='javascript'>location.href='index.php?pag=1'</script>";
                                    break;
                                default:
                                    include_once('inicio.php');
                                    break;
                            }
                            }else
                            include_once('inicio.php');
                        ?>
                        </center>
                    </td>
                </tr>
            </table>
            <hr>
            <font size="2" color="blue">TODOS LOS DERECHOS RESERVADOS <br>Alex Maguana @</font>

        </center>
    </body>
</html>
registro.php
 <?php
session_start();
?>
<!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <?php
            $error="";
            $conexion=mysql_connect("localhost","root","");
            if(!$conexion)
                die('No se establecio la conexion'.mysql_error());
            else
            {
                mysql_select_db("cuentas",$conexion);
                $name=$passw="";
                if (isset($_POST)){
                    if (isset($_POST['user']))
                        $name=$_POST['user'];
                    if (isset($_POST['passw']))
                        $passw=$_POST['passw'];
                    if ($name!="" && $passw!=""){
                        $sql=mysql_query("select * from usuario where nom_usu='$name' and cla_usu='$passw'");
                        if ($fila=mysql_fetch_array($sql)) {
                            $_SESSION['user']=$fila['nom_usu'];
                            $_SESSION['nivel']=$fila['niv_usu'];
                            $_SESSION['activo']=$fila['est_usu'];
                            if ($fila['niv_usu']==1)
                                echo "<script languaje='javascript'>location.href='index.php?pag=3'</script>";
                            else
                                echo "<script languaje='javascript'>location.href='index.php?pag=4'</script>";
                        }else{
                            $error="NO EXISTE USUARIO REGISTRADO";
                        }
                    }
                }
            }
        ?>
        <form method="POST" acction="index.php?pag=2">
            <table width="100%" border="0px" cellpadding="3" cellspacing="3">
                <tr>
                    <td style="" colspan="2"><center><font color=""><h2>REGISTRO</h2></center></font></td>
                </tr>
                <tr>
                    <td><b>USUARIO</b></td>
                    <td><input type="text" id="user" name="user" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>CLAVE</b></td>
                    <td><input type="password" id="passw" name="passw" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><input onclick="
                    var u=document.getElementById('user').value;
                    var c=document.getElementById('passw').value;
                    if (u=='' || c=='')
                        alert('REGISTRE DATOS EN LOS TEXTOS POR FAVOR');
                    " type="submit" name="registro" value="INGRESAR AL SISTEMA"/></b></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><a href="index.php?pag=2">REGISTRAR AL SISTEMA</a></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><font color="red"><?php if (isset($error)) echo $error;?></font></b></center></td>
                </tr>
            </table>
        </form>
    </body>
</html>
inicio.php
 <!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <table width="100%" border="0px" cellpadding="3" cellspacing="3">
            <tr>
                <td style="background: ;heigth:100%" colspan="2"><center><font color="blue"><h1>INICIO DE SISTEMA</h1></center></font></td>
            </tr>
        </table>
    </body>
</html>
usuarios.php
 <?php
    $error="";
    $conexion=mysql_connect("localhost","root","");
    if(!$conexion)
        die('No se establecio la conexion'.mysql_error());
    else
    {
        mysql_select_db("cuentas",$conexion);
        $name=$alias=$passw=$rpassw=$email="";
        if (isset($_POST)){
            if (isset($_POST['name']))
                $name=$_POST['name'];
            if (isset($_POST['alias']))
                $alias=$_POST['alias'];
            if (isset($_POST['passw']))
                $passw=$_POST['passw'];
            if (isset($_POST['rpassw']))
                $rpassw=$_POST['rpassw'];
            if (isset($_POST['email']))
                $email=$_POST['email'];
            if ($name!="" && $alias!="" && $passw!="" && $rpassw!="" && $email!=""){
                if(filter_var($email, FILTER_VALIDATE_EMAIL)){
                    if ($passw==$rpassw){
                        $sql="insert into usuario values('$name','$alias','$passw','$email',3,0)";
                        if (!mysql_query($sql,$conexion))
                            $error="ERROR DE REGISTRO DE USUARIO";
                    }else
                        $error="LAS CLAVES NO COINCIDEN"; 
                }else{
                    $error="ERROR EN REGISTRO DE EMAIL"; 
                }
            }
        }
    }
?>
<!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <form method="POST" action="index.php?pag=2">
            <table width="300px" border="0px" cellpadding="3" cellspacing="3">
                <tr>
                    <td style="" colspan="2"><center><font color=""><h2>REGISTRO DE USUARIO</h2></center></font></td>
                </tr>
                <tr>
                    <td><b>NOMBRE</b></td>
                    <td><input type="text" id="name" name="name" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>ALIAS</b></td>
                    <td><input type="text" id="alias" name="alias" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>CLAVE</b></td>
                    <td><input type="password" id="passw" name="passw" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>CONFIRMAR CLAVE</b></td>
                    <td><input type="password" id="rpassw" name="rpassw" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>EMAIL</b></td>
                    <td><input type="text" id="email" name="email" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><input onclick="
                    var n=document.getElementById('name').value;
                    var a=document.getElementById('alias').value;
                    var p=document.getElementById('passw').value;
                    var r=document.getElementById('rpassw').value;
                    var e=document.getElementById('email').value;
                  
                    if (n=='' || a=='' || e=='')
                        alert('LLENE TODOS LOS REGISTROS PARA ALMACENAR LA INFORMACION DE USUARIO');"
                    type="submit" name="registro" value="REGISTRAR"/></b></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><font color="red"><?php if (isset($error)) echo $error;?></font></b></center></td>
                </tr>
            </table>
        </form>
    </body>
</html>
admin.php
 <!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <table width="100%" border="0px" cellpadding="3" cellspacing="3">
            <tr>
                <td style="heigth:20px" colspan="2">
                    HOLA:
                    <?php
                        if  (isset($_SESSION['user']))
                            echo $_SESSION['user'];
                        else
                            echo "USUARIO SIN REGISTRAR";
                        $conexion=mysql_connect("localhost","root","");
                        if(!$conexion)
                            die('No se establecio la conexion'.mysql_error());
                        else
                        {
                            mysql_select_db("cuentas",$conexion);
                            if (isset($_GET['id'])){
                                $user=$_GET['id'];
                                $nivel=$_GET['v'];
                                $estado=$_GET['x'];
                                $sql="update usuario set niv_usu=$nivel, est_usu=$estado where nom_usu='$user'";
                                if (!mysql_query($sql,$conexion))
                                    $error="ERROR DE ACTUALIZACIÓN DE USUARIO";
                                else
                                    echo "<script languaje='javascript'>location.href='index.php?pag=3'</script>";
                            }
                        }
                    ?>  
                </td>
            </tr>
            <tr>
                <td style="heigth:100%" colspan="2">
                    <table border="1px">
                        <tr>
                            <td>NOMBRE</td>
                            <td>ALIAS</td>
                            <td>CLAVE</td>
                            <td>EMAIL</td>
                            <td>NIVEL</td>
                            <td>ESTADO</td>
                            <td>GUARAR</td>
                        </tr>
                        <?php
                        $error="";
                        $conexion=mysql_connect("localhost","root","");
                        if(!$conexion)
                            die('No se establecio la conexion'.mysql_error());
                        else
                        {
                            mysql_select_db("cuentas",$conexion);
                            $sql=mysql_query("select * from usuario where niv_usu<>1");
                            $i=0;
                            while ($fila=mysql_fetch_array($sql)) {
                                $nom=$fila['nom_usu'];
                                echo "<tr><td>".$fila['nom_usu']."</td>";
                                echo "<td>".$fila['ali_usu']."</td>";
                                echo "<td>".$fila['cla_usu']."</td>";
                                echo "<td>".$fila['ema_usu']."</td>";
                                $nivel=$fila['niv_usu'];
                                echo "<td><SELECT id='valor$i'>
                                           <OPTION VALUE='2'>2</OPTION>
                                           <OPTION VALUE='3'>3</OPTION>
                                           <OPTION VALUE='4'>4</OPTION>
                                        </SELECT><script>document.getElementById('valor$i').value=$nivel</script></td>";
                                if ($fila['est_usu']==1)
                                    echo "<td><input id='chk$i' type='checkbox' checked='true' /></td>";
                                else
                                    echo "<td><input id='chk$i' type='checkbox'/></td>";
                              
                                echo "<td><a href='#' onclick=\"
                                    actualizar('$nom',document.getElementById('valor$i').value,document.getElementById('chk$i').checked);
                                \">GUARAR</a></td></tr>";
                                $i++;
                            }
                        }
                        ?>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>
user.php
<!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <table width="100%" border="0px" cellpadding="3" cellspacing="3">
            <tr>
                <td style="heigth:20px" colspan="2">
                    HOLA:
                    <?php
                        if  (isset($_SESSION['user']))
                            echo $_SESSION['user'];
                        else
                            echo "USUARIO SIN REGISTRAR";
                    ?>   
                </td>
            </tr>
            <tr>
                <td style="heigth:100%" colspan="2">
                    <table border="1px">
                        <tr>
                            <td>NOMBRE</td>
                            <td>ALIAS</td>
                            <td>CLAVE</td>
                            <td>EMAIL</td>
                            <td>NIVEL</td>
                            <td>ESTADO</td>
                        </tr>
                        <?php
                        $error="";
                        $conexion=mysql_connect("localhost","root","");
                        if(!$conexion)
                            die('No se establecio la conexion'.mysql_error());
                        else
                        {
                            mysql_select_db("cuentas",$conexion);
                            $sql=mysql_query("select * from usuario where niv_usu<>1");
                            while ($fila=mysql_fetch_array($sql)) {
                                $nom=$fila['nom_usu'];
                                echo "<tr><td>".$fila['nom_usu']."</td>";
                                echo "<td>".$fila['ali_usu']."</td>";
                                echo "<td>".$fila['cla_usu']."</td>";
                                echo "<td>".$fila['ema_usu']."</td>";
                                $nivel=$fila['niv_usu'];
                                echo "<td>$nivel</td>";
                                if ($fila['est_usu']==1)
                                    echo "<td>Activado</td>";
                                else
                                    echo "<td>Desactivado</td>";
                            }
                        }
                        ?>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>
bbdd.sql
drop TABLE usuario
create TABLE usuario(
nom_usu varchar(50) primary key,
ali_usu varchar(50),
cla_usu varchar(50),
ema_usu varchar(50),
niv_usu int,
est_usu tinyint)
EJECUCION

Al iniciar con el servidor localhost nos muestra la siguiente ventana.

 Al hacer clic en REGISTRAR AL SISTEMA nos muestra la siguiente ventana donde llenamos los siguientes campos y guardamos.


Al entrar como el usuario que ya registramos nos muestra la siguiente tabla con todos los usuarios registrados y sus privilegios  el nivel y estado en que se encuentra.

Al entrar como administrador .


Nos muestra la siguiente tabla donde se puede dar los privilegios el numero de nivel y actibar o desactibar el estado y duardamos.
 Verificamos la cuenta del usuario y vemos que ya tine un nivel 2 y esta activado


miércoles, 29 de enero de 2014

ELIMINAR REGISTROS DE UNA TABLA EN MYSQL


master.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Formulario de validación de usuario</title>
</head>
<div>
<?php
include_once ("cabe.php");
?>
</div>
<div style="height:450px;width:100%">
<table border="0px" width="100%">
    <tr>
        <td colspan="2">
            <center><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=1'>INICIO</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=2'>REGISTRO</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=3'>LISTAR</a>
            <a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=6'>EDITAR</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=7'>ELIMINAR</a></center>
        </td>
    </tr>
    <tr>
        <td width="200px" height="450px">
            <?php
            include_once ("Registros.php");
            ?>
        </td>
        <td>
            <?php
                switch($_GET['id']){
                    case 1:
                        include_once ("contenido.php");
                    break;
                    case 2:
                        include_once ("Registrar.php");
                    break;
                    case 3:
                        include_once ("Reporte.php");
                    break;
                    case 4:
                        include_once("Filtro.php");
                    break;
                    case 5:
                        include_once("Insertar.php");
                    break;
                    case 6:
                        include_once("Actualizar.php");
                    break;
                  
                }
                ?>
        </td>
    </tr>
</table>
</div>
</div>

<br>
<br>
<br>
<br>
<?php
include_once ("pi.php");
?>
<div>
</body>
</html>
cabe.php
<html>
<head>
<title> Pie </title>
</head>
<body bgcolor text="blue">
<hr>
<center><h1> BASE DE DATOS AGENDA </h1></center>
</body>
</html>
Registros.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Formulario de validación de usuario</title>
</head>
<form action="dc.php" method="POST">
        <label for="username"><h2>Usuario</h2></label>
        <input id="username" type="text" name="username" size="20" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
        <label for="passwd"><h2>Contraseña</h2></label>
        <input id="passwd" type="password" name="password" size="20" value="<?php if (isset($_SESSION["clave"])){echo $_SESSION["clave"];}?>"/>
        <br>
        <br>
    <input type="submit" name="Submit" class="button" value="INGRESAR" />
</form>
</body>
</html>
contenido.php
 <html>
<head>
</head>
<body bgcolor text="blue">
<div style="width:100%; height:100%; background:url('agenda.jpg')">
   
</div>
</body>
</html>
Registrar.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Reportes</title>
</head>
<body>
<form action="master.php?id=5" method="POST">
  <fieldset>
  <p>
        <label for="codigo">Codigo</label>
        <input id="codigo" type="text" name="codigo" size="18" value="<?php if (isset($_SESSION["codigo"])){echo $_SESSION["codigo"];}?>"/>
    </p>
   
    <p>
        <label for="username">Nombre</label>
        <input id="nombre" type="text" name="nombre" size="18" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
    </p>
   
    <p>
        <label for="apellido">Apellido</label>
        <input id="apellido" type="text" name="apellido" size="18" value="<?php if (isset($_SESSION["apellido"])){echo $_SESSION["apellido"];}?>"/>
    </p>
    <p>
        <label for="edad">Edad</label>
        <input id="edad" type="text" name="edad" size="18" value="<?php if (isset($_SESSION["edad"])){echo $_SESSION["edad"];}?>"/>
    </p>
        <p>
        <label for="correo">Direccion</label>
        <input id="direccion" type="text" name="direccion" size="18" value="<?php if (isset($_SESSION["direccion"])){echo $_SESSION["direccion"];}?>"/>
    </p>
    <p>
        <label for="correo">Telefono</label>
        <input id="telefono" type="text" name="telefono" size="18" value="<?php if (isset($_SESSION["telefono"])){echo $_SESSION["telefono"];}?>"/>
    <p>
    <p>   
       <label for="ciudad">Ciudad   
       <select name="ciu">
       <option value="Azogues">Azogues
        <option value="Biblian">Biblian
         <option value="Cañar">Cañar
       </select>
       </label>      
    </p>
        <p>   
            <label for="ciudad">Sexo
       <select name="sex">
       <option>M
        <option>F
       </select>
       </label>   
    </p>
        <input type="submit" name="b2" class="button" value="INGRESAR" /> </center>
    </p>
  </fieldset>
</form>
</body>
</html>
  Reporte.php
 <html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Reportes</title>
</head>
<body>
<form action="master.php?id=4" method="POST">
  <fieldset>
    <p>       
       <label for="username">FILTRAR POR:</label>
    </p>
   
    <p>
        <label for="username">Nombre</label>
        <input id="nombre" type="text" name="nombre" size="18" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
    </p>
   
    <p>
        <label for="passwd">Apellido</label>
        <input id="apellido" type="text" name="apellido" size="18" value="<?php if (isset($_SESSION["apellido"])){echo $_SESSION["apellido"];}?>"/>
    </p>
        <p>
        <label for="correo">Direccion</label>
        <input id="direccion" type="text" name="direccion" size="18" value="<?php if (isset($_SESSION["direccion"])){echo $_SESSION["direccion"];}?>"/>
    </p>
    <p>
        <label for="correo">Telefono</label>
        <input id="telefono" type="text" name="telefono" size="18" value="<?php if (isset($_SESSION["telefono"])){echo $_SESSION["telefono"];}?>"/>
    <p>   
       <input type="radio" name="b3" value="1" class="imputradio" checked /><label for="username">ASENDENTE</label>
        <br>
        <input type="radio" name="b3" value="2" class="imputradio"/><label for="username">DESENDENTE</label>
    </p>
    <p>
        <input type="submit" name="b2" class="button" value="FILTRAR" /> <input type="submit" name="b1" class="button" value="LISTAR TODO" /></center>
    </p>
  </fieldset>
</form>
</body>
</html>
Filtro.php
 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
session_start();
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
{
die ('No se establecio la conexion'.mysql_error());
}
else
{
    mysql_select_db("bddagenda",$conexion);
    $order="asc";
    if (isset($_POST['b3'])){
        if ($_POST['b3']=="2")
            $order="desc";
    }
    $activo=false;
    if (isset($_POST['b2'])){
        $value=$_POST['nombre'].$_POST['apellido'].$_POST['direccion'].$_POST['telefono'];
        $sql=mysql_query("select * from agenda where concat(Nombre,Apellido,Direccion,telefono) like concat('%','$value','%') order by Nombre $order");
        $activo=true;
    }
    if (isset($_POST['b1'])){
        $sql=mysql_query("select * from agenda order by Nombre $order");
        $activo=true;
    }   
    if (isset($_POST['b4'])){
       
        $nom=$_POST['nombre'];
        $ape=$_POST['apellido'];
        $dir=$_POST['direccion'];
        $tel=$_POST['telefono'];
        $datos="insert into agenda values(9,'$nom','$ape',99,'$tel','$dir')";
        mysql_query($datos) or die("No se puede grabar");
        echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
    }
    if ($activo==true){
        echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td></tr>";
        while($fila=mysql_fetch_array($sql))
        {
            echo "<tr>";
            echo "<td>".$fila['idagenda'],''."</td>";
            echo "<td>".$fila['Nombre'],''."</td>";
            echo "<td>".$fila['Apellido'],''."</td>";
            echo "<td>".$fila['edad'],''."</td>";
            echo "<td>".$fila['telefono'],''."</td>";
            echo "<td>".$fila['Direccion'],''."</td>";
            echo "</tr>";
        }
        echo "</table></center";
    }
    echo "<br><br><br>";
}
?>
<form action="master.php?id=3" method="POST">
    <center><input type="submit" name="Submit" class="button" value="REGRESAR" /></center>
</form>
</body>
Insertar.php 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
session_start();
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
{
die ('No se establecio la conexion'.mysql_error());
}
else
{
    mysql_select_db("bddagenda",$conexion);
    if (isset($_POST['b2'])){
        $cod=$_POST['codigo'];
        $nom=$_POST['nombre'];
        $ape=$_POST['apellido'];
        $dir=$_POST['direccion'];
        $tel=$_POST['telefono'];
        $eda=$_POST['edad'];
        $ciu=$_POST['ciu'];
        $sex=$_POST['sex'];
        $sql=mysql_query("select *from agenda where idagenda=$cod");
        if($fila=mysql_fetch_array($sql)){
            $datos="update agenda set Nombre='$nom',Apellido='$ape',edad=$eda,telefono='$tel',Direccion='$dir',Ciudad='$ciu',Sexo='$sex' where idagenda=$cod";
            mysql_query($datos) or die("No se puede grabar");
            echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
        }else
        {
            $datos="insert into agenda values($cod,'$nom','$ape',$eda,'$tel','$dir','$ciu','$sex')";
            mysql_query($datos) or die("No se puede grabar");
            echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
        }
    }
    echo "<br><br><br>";
}
?>
<form action="master.php?id=2" method="POST">
    <center><input type="submit" name="Submit" class="button" value="REGRESAR" /></center>
</form>
</body>
</html>
pi.php
<html>
<head>
<title> Pie </title>
</head>
<body bgcolor text="blue">
<hr>
<center><h1 style="text-align:right"> Alexandra Maguana </h1></center>
</body>
</html>
Actulizar.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
   {
    die ('No se establecio la coneccion'.mysql_error());
   }
   else
   {
     echo("");
   }
    echo "<br>";
  
  mysql_select_db("bddagenda",$conexion);

  $sql=mysql_query("select *from agenda");
  echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td><td>CIUDAD</td><td>SEXO</td><td>ACCION</td></tr>";
        while($fila=mysql_fetch_array($sql))
        {
            $id=$fila['idagenda'];
            echo "<tr>";
            echo "<td>".$fila['idagenda'],''."</td>";
            echo "<td>".$fila['Nombre'],''."</td>";
            echo "<td>".$fila['Apellido'],''."</td>";
            echo "<td>".$fila['edad'],''."</td>";
            echo "<td>".$fila['telefono'],''."</td>";
            echo "<td>".$fila['Direccion'],''."</td>";
            echo "<td>".$fila['Ciudad'],''."</td>";
            echo "<td>".$fila['Sexo'],''."</td>";
            echo "<td>"."<a href='?id=2&ida=$id'>"."Editar"."</td>";
            echo "</tr>";
        }
        echo "</table></center";
    echo "<br><br><br>";
?>


Eliminar.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
   {
    die ('No se establecio la coneccion'.mysql_error());
   }
   else
   {
     echo("<br>");
   }
    echo "<br>";
  
   mysql_select_db("bddagenda",$conexion);
 
  if (isset($_GET['ida'])){
    $codigo=$_GET['ida'];
    $datos="delete from agenda where idagenda=$codigo";
    mysql_query($datos) or die("No se puede eliminar");
    echo "LA ELIMINACION SE CUMPLIO EXITOSAMENTE...BY OK";
  }
  $sql=mysql_query("select *from agenda");
  echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td><td>CIUDAD</td><td>SEXO</td><td>ACCION</td></tr>";
        while($fila=mysql_fetch_array($sql))
        {
            $id=$fila['idagenda'];
            echo "<tr>";
            echo "<td>".$fila['idagenda'],''."</td>";
            echo "<td>".$fila['Nombre'],''."</td>";
            echo "<td>".$fila['Apellido'],''."</td>";
            echo "<td>".$fila['edad'],''."</td>";
            echo "<td>".$fila['telefono'],''."</td>";
            echo "<td>".$fila['Direccion'],''."</td>";
            echo "<td>".$fila['Ciudad'],''."</td>";
            echo "<td>".$fila['Sexo'],''."</td>";
            echo "<td>"."<a href='?id=8&ida=$id'>"."Eliminar"."</td>";
            echo "</tr>";
        }
        echo "</table></center";
    echo "<br><br><br>";
?>
Confirmar.php
<html>
<head>
<title>BorrarCookie</title>
</head>
<body>
<form action="Eliminar.php" method="post">
<h1> Desea eliminar el campo seleccionado</h1>
    <br>
    <br>
    <br>
    <br>
   <p>
        <label for="Si">SI</label>
        <input type="radio" name="opcion" value="SI">
        <br>
        <label for="No">NO</label>
        <input type="radio" name="opcion" value="SI">
    </p>
    <br>
    <br>
<input type="submit" value="CONFIRMAR">
</form>
</body>
</html>
 
EJECUCIÓN
Al iniciar con el servidor nos aparece esta ventana. 



Al selecionar una de las opciones que se encuentran el boton INICIO nos muestra la pantalla principal y REGISTRO muestra la siguiente ventana donde llenamos sus campos y pulsamos INGRESAR.

 
Si el ingreso fue correcta nos muestra el siguiente pantalla.
 El boton listar nos muestra la sguiente ventana  donde podemos asignar el campo por el cual desea filtrar ya sea en orden asendente y desendente.
 El boton listar nos muestra todos los registros.
 El boton filtrar para ello tenemos que llenar el campo por el cual deseamos filtrar por ejem:por el nombre que empiecen con Mar nos da el siguiente resultado.

Al seleccionar ACTULIZAR nos muestra el siguiente formulario  con todos los registros.


Al pulsar en la pate derecha de la tabla en EDITAR  nos muestra el siguiente formulario con el registro que se ha seleccionado .
 Editamos los campos que deseamos y pulsamos  guardar.

Si se guarda correctamente nos muestra el siguiente mensaje.
 

Para verificar que se haya modificado vamos a INFORMES y listar todo y nos muestra esta ventana con todos los registros.
 Al seleccionar ELIMINAR nos muestra el siguiente formulario  con todos los registros.


Al pulsar en la pate derecha de la tabla en ELIMINAR  nos muestra el siguiente formulario con dos opciones que tenemos que seleccionar SI y  NO .
 Si seleccionamos SI y precionamos confirmar nos muestra la siguiente tabla ya con el registro eliminado.


martes, 28 de enero de 2014

EDITAR DATOS EN UNA BDD CON PHP


master.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Formulario de validación de usuario</title>
</head>
<div>
<?php
include_once ("cabe.php");
?>
</div>
<div style="height:450px;width:100%">
<table border="0px" width="100%">
    <tr>
        <td colspan="2">
            <center><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=1'>INICIO</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=2'>REGISTRO</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=3'>LISTAR</a>
            <a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=6'>EDITAR</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=7'>ELIMINAR</a></center>
        </td>
    </tr>
    <tr>
        <td width="200px" height="450px">
            <?php
            include_once ("Registros.php");
            ?>
        </td>
        <td>
            <?php
                switch($_GET['id']){
                    case 1:
                        include_once ("contenido.php");
                    break;
                    case 2:
                        include_once ("Registrar.php");
                    break;
                    case 3:
                        include_once ("Reporte.php");
                    break;
                    case 4:
                        include_once("Filtro.php");
                    break;
                    case 5:
                        include_once("Insertar.php");
                    break;
                    case 6:
                        include_once("Actualizar.php");
                    break;
                  
                }
                ?>
        </td>
    </tr>
</table>
</div>
</div>

<br>
<br>
<br>
<br>
<?php
include_once ("pi.php");
?>
<div>
</body>
</html>
cabe.php
<html>
<head>
<title> Pie </title>
</head>
<body bgcolor text="blue">
<hr>
<center><h1> BASE DE DATOS AGENDA </h1></center>
</body>
</html>
Registros.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Formulario de validación de usuario</title>
</head>
<form action="dc.php" method="POST">
        <label for="username"><h2>Usuario</h2></label>
        <input id="username" type="text" name="username" size="20" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
        <label for="passwd"><h2>Contraseña</h2></label>
        <input id="passwd" type="password" name="password" size="20" value="<?php if (isset($_SESSION["clave"])){echo $_SESSION["clave"];}?>"/>
        <br>
        <br>
    <input type="submit" name="Submit" class="button" value="INGRESAR" />
</form>
</body>
</html>
contenido.php
 <html>
<head>
</head>
<body bgcolor text="blue">
<div style="width:100%; height:100%; background:url('agenda.jpg')">
   
</div>
</body>
</html>
Registrar.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Reportes</title>
</head>
<body>
<form action="master.php?id=5" method="POST">
  <fieldset>
  <p>
        <label for="codigo">Codigo</label>
        <input id="codigo" type="text" name="codigo" size="18" value="<?php if (isset($_SESSION["codigo"])){echo $_SESSION["codigo"];}?>"/>
    </p>
   
    <p>
        <label for="username">Nombre</label>
        <input id="nombre" type="text" name="nombre" size="18" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
    </p>
   
    <p>
        <label for="apellido">Apellido</label>
        <input id="apellido" type="text" name="apellido" size="18" value="<?php if (isset($_SESSION["apellido"])){echo $_SESSION["apellido"];}?>"/>
    </p>
    <p>
        <label for="edad">Edad</label>
        <input id="edad" type="text" name="edad" size="18" value="<?php if (isset($_SESSION["edad"])){echo $_SESSION["edad"];}?>"/>
    </p>
        <p>
        <label for="correo">Direccion</label>
        <input id="direccion" type="text" name="direccion" size="18" value="<?php if (isset($_SESSION["direccion"])){echo $_SESSION["direccion"];}?>"/>
    </p>
    <p>
        <label for="correo">Telefono</label>
        <input id="telefono" type="text" name="telefono" size="18" value="<?php if (isset($_SESSION["telefono"])){echo $_SESSION["telefono"];}?>"/>
    <p>
    <p>   
       <label for="ciudad">Ciudad   
       <select name="ciu">
       <option value="Azogues">Azogues
        <option value="Biblian">Biblian
         <option value="Cañar">Cañar
       </select>
       </label>      
    </p>
        <p>   
            <label for="ciudad">Sexo
       <select name="sex">
       <option>M
        <option>F
       </select>
       </label>   
    </p>
        <input type="submit" name="b2" class="button" value="INGRESAR" /> </center>
    </p>
  </fieldset>
</form>
</body>
</html>
  Reporte.php
 <html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Reportes</title>
</head>
<body>
<form action="master.php?id=4" method="POST">
  <fieldset>
    <p>       
       <label for="username">FILTRAR POR:</label>
    </p>
   
    <p>
        <label for="username">Nombre</label>
        <input id="nombre" type="text" name="nombre" size="18" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
    </p>
   
    <p>
        <label for="passwd">Apellido</label>
        <input id="apellido" type="text" name="apellido" size="18" value="<?php if (isset($_SESSION["apellido"])){echo $_SESSION["apellido"];}?>"/>
    </p>
        <p>
        <label for="correo">Direccion</label>
        <input id="direccion" type="text" name="direccion" size="18" value="<?php if (isset($_SESSION["direccion"])){echo $_SESSION["direccion"];}?>"/>
    </p>
    <p>
        <label for="correo">Telefono</label>
        <input id="telefono" type="text" name="telefono" size="18" value="<?php if (isset($_SESSION["telefono"])){echo $_SESSION["telefono"];}?>"/>
    <p>   
       <input type="radio" name="b3" value="1" class="imputradio" checked /><label for="username">ASENDENTE</label>
        <br>
        <input type="radio" name="b3" value="2" class="imputradio"/><label for="username">DESENDENTE</label>
    </p>
    <p>
        <input type="submit" name="b2" class="button" value="FILTRAR" /> <input type="submit" name="b1" class="button" value="LISTAR TODO" /></center>
    </p>
  </fieldset>
</form>
</body>
</html>
Filtro.php
 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
session_start();
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
{
die ('No se establecio la conexion'.mysql_error());
}
else
{
    mysql_select_db("bddagenda",$conexion);
    $order="asc";
    if (isset($_POST['b3'])){
        if ($_POST['b3']=="2")
            $order="desc";
    }
    $activo=false;
    if (isset($_POST['b2'])){
        $value=$_POST['nombre'].$_POST['apellido'].$_POST['direccion'].$_POST['telefono'];
        $sql=mysql_query("select * from agenda where concat(Nombre,Apellido,Direccion,telefono) like concat('%','$value','%') order by Nombre $order");
        $activo=true;
    }
    if (isset($_POST['b1'])){
        $sql=mysql_query("select * from agenda order by Nombre $order");
        $activo=true;
    }   
    if (isset($_POST['b4'])){
       
        $nom=$_POST['nombre'];
        $ape=$_POST['apellido'];
        $dir=$_POST['direccion'];
        $tel=$_POST['telefono'];
        $datos="insert into agenda values(9,'$nom','$ape',99,'$tel','$dir')";
        mysql_query($datos) or die("No se puede grabar");
        echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
    }
    if ($activo==true){
        echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td></tr>";
        while($fila=mysql_fetch_array($sql))
        {
            echo "<tr>";
            echo "<td>".$fila['idagenda'],''."</td>";
            echo "<td>".$fila['Nombre'],''."</td>";
            echo "<td>".$fila['Apellido'],''."</td>";
            echo "<td>".$fila['edad'],''."</td>";
            echo "<td>".$fila['telefono'],''."</td>";
            echo "<td>".$fila['Direccion'],''."</td>";
            echo "</tr>";
        }
        echo "</table></center";
    }
    echo "<br><br><br>";
}
?>
<form action="master.php?id=3" method="POST">
    <center><input type="submit" name="Submit" class="button" value="REGRESAR" /></center>
</form>
</body>
Insertar.php 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
session_start();
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
{
die ('No se establecio la conexion'.mysql_error());
}
else
{
    mysql_select_db("bddagenda",$conexion);
    if (isset($_POST['b2'])){
        $cod=$_POST['codigo'];
        $nom=$_POST['nombre'];
        $ape=$_POST['apellido'];
        $dir=$_POST['direccion'];
        $tel=$_POST['telefono'];
        $eda=$_POST['edad'];
        $ciu=$_POST['ciu'];
        $sex=$_POST['sex'];
        $sql=mysql_query("select *from agenda where idagenda=$cod");
        if($fila=mysql_fetch_array($sql)){
            $datos="update agenda set Nombre='$nom',Apellido='$ape',edad=$eda,telefono='$tel',Direccion='$dir',Ciudad='$ciu',Sexo='$sex' where idagenda=$cod";
            mysql_query($datos) or die("No se puede grabar");
            echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
        }else
        {
            $datos="insert into agenda values($cod,'$nom','$ape',$eda,'$tel','$dir','$ciu','$sex')";
            mysql_query($datos) or die("No se puede grabar");
            echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
        }
    }
    echo "<br><br><br>";
}
?>
<form action="master.php?id=2" method="POST">
    <center><input type="submit" name="Submit" class="button" value="REGRESAR" /></center>
</form>
</body>
</html>
pi.php
<html>
<head>
<title> Pie </title>
</head>
<body bgcolor text="blue">
<hr>
<center><h1 style="text-align:right"> Alexandra Maguana </h1></center>
</body>
</html>
Actulizar.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
   {
    die ('No se establecio la coneccion'.mysql_error());
   }
   else
   {
     echo("");
   }
    echo "<br>";
  
  mysql_select_db("bddagenda",$conexion);

  $sql=mysql_query("select *from agenda");
  echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td><td>CIUDAD</td><td>SEXO</td><td>ACCION</td></tr>";
        while($fila=mysql_fetch_array($sql))
        {
            $id=$fila['idagenda'];
            echo "<tr>";
            echo "<td>".$fila['idagenda'],''."</td>";
            echo "<td>".$fila['Nombre'],''."</td>";
            echo "<td>".$fila['Apellido'],''."</td>";
            echo "<td>".$fila['edad'],''."</td>";
            echo "<td>".$fila['telefono'],''."</td>";
            echo "<td>".$fila['Direccion'],''."</td>";
            echo "<td>".$fila['Ciudad'],''."</td>";
            echo "<td>".$fila['Sexo'],''."</td>";
            echo "<td>"."<a href='?id=2&ida=$id'>"."Editar"."</td>";
            echo "</tr>";
        }
        echo "</table></center";
    echo "<br><br><br>";
?>

 
EJECUCIÓN
Al iniciar con el servidor nos aparece esta ventana.
Al selecionar una de las opciones que se encuentran el boton INICIO nos muestra la pantalla principal y REGISTRO muestra la siguiente ventana donde llenamos sus campos y pulsamos INGRESAR.

 
Si el ingreso fue correcta nos muestra el siguiente pantalla.
 El boton listar nos muestra la sguiente ventana  donde podemos asignar el campo por el cual desea filtrar ya sea en orden asendente y desendente.
 El boton listar nos muestra todos los registros.
 El boton filtrar para ello tenemos que llenar el campo por el cual deseamos filtrar por ejem:por el nombre que empiecen con Mar nos da el siguiente resultado.

Al seleccionar ACTULIZAR nos muestra el siguiente formulario  con todos los registros.


Al pulsar en la pate derecha de la tabla en EDITAR  nos muestra el siguiente formulario con el registro que se ha seleccionado .
 Editamos los campos que deseamos y pulsamos  guardar.

Si se guarda correctamente nos muestra el siguiente mensaje.
 

Para verificar que se haya modificado vamos a INFORMES y listar todo y nos muestra esta ventana con todos los registros.