elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  mi agenda en php con mysql
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: mi agenda en php con mysql  (Leído 5,522 veces)
phirkan

Desconectado Desconectado

Mensajes: 1


Ver Perfil
mi agenda en php con mysql
« en: 28 Marzo 2013, 22:52 pm »

Buenas, hice un cursillo de php y nos mandaron hacer una agenda para gestionarlo  mysql y con ficheros. La verdad es que me quedó bastante sencillito de comprender, aquí os dejo mi agenda en mysql, si a alguien le interesa como gestionarlo con ficheros que me lo pida sin problemas. ^_^

Solo tendreis que crear la base de datos en mysql a traves del MyAdmin, o  por comandos sql;

Create database agenda; // y listo xD

<?php
@   $conexion = new mysqli("localhost","root","tucontraseña","agenda");
         if ($ERROR = mysqli_connect_errno()){
        echo "Error de conexión";
        echo "error :$error";
    }
      else {$sql = 'create table if not exists agenda_antonio(nombre varchar(20), telefono int(9), email varchar(40))';
            $conexion->query($sql);
            }
 
   


 echo "<fieldset>
 <legend>AGENDA!</legend><br>

<br>  <form action=\"\" name=\"form\" method=\"POST\">

//En el Onfocus(cuando hacemos clic en el box["input type='text'"]) vemos un poquito de javascript
Nombre: <input type=\"text\" value=\"Introduce el nombre\"    name=\"nombre\"      onFocus=\"if (this.value=='Introduce el nombre') this.value=''\"><br>

 telefono: <input type=\"text\" value=\"Introduce telefono\" name=\"telefono\" onFocus=\"if (this.value=='Introduce telefono') this.value=''\"><br>

 e-mail: <input type=\"text\" value=\"Introduce email\" name=\"email\" onFocus=\"if (this.value=='Introduce email') this.value=''\"><br>

  <input type=\"submit\" value=\"Agregar\" name=\"agregar\" id=\"agregar\">
  <input type=\"submit\" value=\"Listar todo\" name=\"listar\" id=\"listar\"><br>
  <input type=\"submit\" value=\"Borrar registro\" name=\"borrar\" id=\"borrar\">
  <input type=\"submit\" value=\"Borrar todo\" name=\"borrart\" id=\"borrart\">
           </form>
</fieldset>";
 
 if(isset($_POST['agregar'])){
    //Definimos la consulta(insert)
    $meter = "insert into agenda_antonio values('".$_POST['nombre']."','".$_POST['telefono']."','".$_POST['email']."')";
    $conexion->query($meter);
    echo "<br><p align=center>El contacto '".$_POST['nombre']."' se ha agregado.</p><br>";
   

                     //Para que aparezca la tabla cuando agregamos un registro
    $TONTA = "Select * from agenda_antonio";
    $CAMPO=$conexion->query($TONTA);
@        $FILA=$CAMPO->fetch_object();
   
    echo "<table border=1 align=center>";
                    echo "<tr  align=center>";
                    echo "<th width=\"100\">";
                    echo "Nombre";
                    echo "</th>";
                    echo "<th>";
                    echo "Telefono";
                    echo "</th>";
                    echo "<th width=\"200\">";
                    echo "Web";
                    echo"</th>";
   
                     while ($FILA){
                    echo "<tr align=center>";
                    echo "<td>";
                    echo $FILA->nombre;
                    echo "</td>";           
                    echo "<td>";
                    echo $FILA->telefono;
                    echo "</td>";
                    echo "<td>";
                    echo $FILA->email;
                    echo "</td>";
                    echo "</tr>";
                    echo "</table>";
                    $FILA=$CAMPO->fetch_object();


}

    }
   
  if(isset($_POST['listar'])){
   
 
                     //Definimos la consulta(select)
    $TONTA = "Select * from agenda_antonio";
    $CAMPO=$conexion->query($TONTA);
@        $FILA=$CAMPO->fetch_object();
        //si la tabla no tiene ningun contacto
    if(!$FILA)
{echo "<p align=center>No existe ningún contacto todavia.</p>";}
    else{
   
    echo "<table border=1 align=center>";
                    echo "<tr  align=center>";
                    echo "<th width=\"100\">";
                    echo "Nombre";
                    echo "</th>";
                    echo "<th>";
                    echo "Telefono";
                    echo "</th>";
                    echo "<th width=\"200\">";
                    echo "Web";
                    echo"</th>";
   
                     while ($FILA){
                    echo "<tr align=center>";
                    echo "<td>";
                    echo $FILA->nombre;
                    echo "</td>";           
                    echo "<td>";
                    echo $FILA->telefono;
                    echo "</td>";
                    echo "<td>";
                    echo $FILA->email;
                    echo "</td>";
                    echo "</tr>";
                    echo "</table>";
                    $FILA=$CAMPO->fetch_object();}
                }

}


if(isset($_POST['borrar'])){

    echo "<fieldset> <legend>Borrar contacto!</legend><br><br></tittle><form action=\"\" name=\"form\" method=\"POST\">
 Nombre: <input type=\"text\" value=\"Introduce el nombre\" name=\"nom\" onFocus=\"if (this.value=='Introduce el nombre') this.value=''\"><br>";
 
  echo "<input type=\"submit\" value=\"Borrar registro\" name=\"borra\" id=\"borra\"></fieldset>";
      echo " NOTA: Introduce el nombre del contacto completo que quieres borrar:";

}
if(isset($_POST['borra'])){
    //Definimos la consulta(delete)
    $borra = "Delete from agenda_antonio where nombre='".$_POST['nom']."' ";
    $conexion->query($borra);
    echo "Se ha borrado '".$_POST['nom']."' .";}

if(isset($_POST['borrart'])){
    //Definimos la consulta(delete)
    $borrat = "Delete from agenda_antonio;";
    $conexion->query($borrat);
    echo "Se han borrado todos los contactos.";
}
?>

 ;-)


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Agenda bat V1 by my
Scripting
J3FFR3Y .4 C3D3Ñ0 0 3,733 Último mensaje 17 Diciembre 2006, 21:46 pm
por J3FFR3Y .4 C3D3Ñ0
Agenda java « 1 2 »
Java
Burnhack 13 52,045 Último mensaje 6 Marzo 2008, 00:47 am
por Burnhack
Php y mysql para agenda
PHP
dark_sargon 4 15,431 Último mensaje 7 Marzo 2009, 04:30 am
por dark_sargon
Agenda telefonica
Programación C/C++
roma7776 1 1,525 Último mensaje 1 Septiembre 2023, 01:50 am
por Locura_23
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines