Вы находитесь на странице: 1из 6

Código de conexión base de dato

<?php
$cn=mysql_connect("localhost","root","123456789")or die("Error en Conexion");
$db=mysql_select_db("dg_motor2")or die("Error en Db");
return($cn);
return($db);
?>

Código de agregar

<?php
include("conexion.eliminar.php");
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ALTAS</title>
<style type="text/css">
body {
background-image: url(imagenes/seamless-vector-pattern-with-decorative-brushed-thin-
lines-in-white-and-grey-colors-texture-for-web-print-wallpaper-wedding_135309380.jpg);
}
</style>
</head>

<body onLoad="carga();">
<header>

<center><h2>FORMULARIO ALTA DE EMPLEADOS</h2></center><br><br>


<a href="index.html">MENU PRINCIPAL</a><br><br>
<br><br>

</header>

<div id="leo">
<section id="leon">

<section id="leone">

<?php
$var="";
$var1="";
$var2="";
$var3="";
$var4="";

if(isset($_POST["btn1"])){
$btn=$_POST["btn1"];

if($btn=="Buscar"){

$sql="select * from listaempleado where Cod_emplea='$bus'";


$cs=mysql_query($sql,$cn);
while($resul=mysql_fetch_array($cs)){
$var=$resul[0];
$var1=$resul[1];
$var2=$resul[2];
$var3=$resul[3];
$var4=$resul[4];
}
if($var4=="Masculino"){
$var4="selected";
}

}
if($btn=="Agregar"){
$cod=$_POST["txtcod"];
$nom=$_POST["txtnom"];
$ape=$_POST["txtape"];
$tel=$_POST["txttel"];
$sex=$_POST["cbosex"];
$sql="insert into listaempleado values ('$cod','$nom','$ape','$tel','$sex')";

$cs=mysql_query($sql,$cn);
echo "<script> alert('empleado registrado correctamente');</script>";
}

}
?>
Código de formulario

<form name="fe" action="" method="post">


<center>
<table border="2">
<tr>
<td>Cod_empleado</td>
<td><input type="text" name="txtcod" value="<?php echo $var?>" /></td>
</tr>

<tr>
<td>Nombre</td>
<td><input type="text" name="txtnom" value="<?php echo $var1?>"/></td>
</tr>
<tr>
<td>Apellido</td>
<td><input type="text" name="txtape" value="<?php echo $var2?>"/></td>
</tr>
<tr>
<td>Telefono;</td>
<td><input type="text" name="txttel" value="<?php echo $var3?>"/></td>
</tr>
<td>Sexo</td>
<td><select name="cbosex">
<option>Femenino</option>
<option <?php echo $var4?> >Maculino</option>
</select></td>
</tr>
</table>
<br>
<tr align="center"><td colspan="2">
<input type="submit" name="btn1"value="Agregar"/></td></tr>

</table>

Вам также может понравиться