Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/06/2007, 08:37
albina
 
Fecha de Ingreso: agosto-2005
Mensajes: 21
Antigüedad: 18 años, 9 meses
Puntos: 0
Re: Php con MysqlFront

Carloshuchim: Aca va el código, este pertenece al formulario donde el usuario añade registros a la Bd.

<?php
/*definimos la funcion formulario que pedira la informacion necesaria*/
function formulario()
{?>
<center><form action="anadcli.php" method=post>
<b> Nombre </b> <input type=text name=nombre maxlength="20"><br>
<b>Primer apellido</b> <input type =text name=ape1 maxlength="15"><br>
<b> Segundo apellido </b> <input type=text name=ape2 maxlength="15"><br>
<b>DNI</b> <input type =text name=dni maxlength="10"><br>
<b> Estado civil </b> <input type=text name=civil value=soltero> Soltero
<input type=text name=civil value=casado> Casado <br>
<b>Domicilio</b> <input type =text name=domicilio maxlength="50"><br>
<b>Localidad</b> <input type =text name=localidad maxlength="15"><br>
<b>Provincia</b> <input type =text name=provincia maxlength="15"><br>
<b>Empresa</b> <input type =text name=empresa maxlength="30"><br>
<b>Telefono</b> <input type =text name=telef maxlength="11"><br>
<b>Telefono movil</b> <input type =text name=telfax maxlength="11"><br>
<b>Fax</b> <input type =text name=fax maxlength="11"><br>
<b>Comentario</b> <textarea name=coment cols=30 rows=10></textarea><br>

<input type=hidden name=v value=1> <input type =reset name=reset Value =reset>
<input type submit name=añadir value=AÑADIR></font>
</form>
</center>
<?php }

/* definimos la funcion añadir donde se añadira la informacion a la base de datos.
Es necesario pasar las variables que cotienen la informacion a añadir*/

function anadir($nombre,$ape1,$ape2,$dni,$civil,$domicilio, $localidad,$provincia,$empresa,$telef,$teleffax,$f ax,$coment)
{
include("conectar.php");
$res=mysql_query("insert into cliente(nombre, apellido1,apellido2,dni,civil,domicilio,localidad, provincia,empresa,telef,teleffax,fax,coment)
values('$nombre','$ape1','$ape2','$dni','$civil',' $domicilio','$localidad','$provincia','$empresa',' $telef','$teleffax','$fax','$coment')",$c);
if ($res==0)
{ ?>
<b><center> error al insertar la informacion </center></b><p><center> <a href=inicio.php><b> volver</b></a></center>
<?php exit;
}
?>
<center><b> el nuevo cliente ha sido añadido correctamente.<p> <center><a href=inicio.php><b> volver</b></a></center>
<?php }

/* si no existe $v se ejecutara la funcion funcionario que pedira la informacion necesaria y dara valor 1 a $v.
Si existe $v procederemos a añadir en la base de datos la informacion que ofrece el formulario */

if (empty($v))
{
formulario();
}
else
{
anadir($nombre,$ape1,$ape2,$dni,$civil,$domicilio, $localidad,$provincia,$empresa,$telef,$teleffax,$f ax,$coment);
}
?>


Espero se entienda, gracias.