You are on page 1of 3

CONEXION

<?
function conectar()
$cn=mysql_connect("localhost","root","") or die(error servidor);
$db=mysql_select_db("contactos") or die ("error base datos");
if(($cn) and ($db))
return tru;
else
return false;
?>

FORMULARIO
<body>
<form name=form1 method="post">
Nombres:<input name="txtxnombres" type="text" size="60px">
apellidos:<input name="txtxapellidos" type="text" size="60px">
direccion:<input name="txtxdireccion" type="text" size="60px">
<input type="submit" name="Registrar">
</form>
</body>
<?php
if(($_post["txtnombres"] !="")&& ($_post["txtapellidos"] !="")&&($_post["txtdire
ccion"] !=""))
{
inclue_once("contacto.php");
$cont=new contacto($_post["txtnombres"],($_post["txtapellidos"],($_post[
"txtdireccion"]);
if($con->registro de contacto())
$msj="registro correcto";
else
$msj="registro no correcto";
<script>window.alert('".$msj."')</script>
}
else
{
$msj="ingrese todo los datos";
<script>window.alert('".$msj."')</script>
}
?>

CONTACTO
<?php
include_once("conexion.php");
class contacto
{
private $nombres;
private $apellidos;
private $direccion;
function contacto($nom,$ape,$dir)
{
$this->nombres=$nom;
$this->apellidos=$ape;
$this->direccion=$dir;
}
function registrarContacto()
{
if(conectar())
{
$sql="INSERT INTO contacto VALUES('','".$this->nombres."','".$this->ap
ellidos."','".$this->direccion."')";
$ejecutar_sql=mysql_query($sql);
if(mysql_affected_rows())
return true;
else
return false;
}//fin de if
}
function listarContacto()
{
if(conectar())
{
$sql="Select * from contacto";
$ejecutar_sql=mysql_query($sql);
$contactos=array();
while($cont=mysql_fetch_assoc($ejecutar_sql))
{
$contactos[]=$cont;
}
return $contactos;
}
}
function getcontacto($cod)
{
if(conectar())
{
$sql="Select * from contacto where codcontacto='".$cod."
'";
$ejecutar_sql=mysql_query($sql);
$datos=mysql_fetch_array($ejecutar_sql);
return $datos;
}
}
function actualizarcontacto($nom,$ape,$dir,$cod)
{
if(conectar())
{
$sql="update contacto set nombres='".$nom."',apellidos='
".$ape."',direccion='".$dir."' where codcontacto='".$cod."'";
$ejecutar_sql=mysql_query($sql);
if(mysql_affected_rows())
return true;
else
return false;
}
}
function eliminarcontacto($cod)
{
if(conectar())
{
$sql="delete from contacto where codcontacto='".$cod."'"
;
$ejecutar_sql=mysql_query($sql);
if(mysql_affected_rows())
return true;
else
return false;
}
}
}
?>
ACTUALIZAR

You might also like