<html>
<head>
</head>
<body>
<?php
include 'conexion.php';
$db = mysql_pconnect($host, $user, $pass) or die('No hay conexion a la BD');
mysql_select_db($database, $db);
$php_self= $_SERVER['PHP_SELF'];
if ($_POST['btnGuardar']) {
$apellido = $_POST['codigo'];
$nombre = $_POST['nombre'];
$fech_compra = $_POST['fech_compra'];
$precio = $_POST['precio'];
$sql_insert = "INSERT INTO compras (`codigo`, `nombre`, `fech_compra`, `precio`) VALUES ('$codigo', '$nombre', '$fech_compra', '$precio');";
$result = mysql_query($sql_insert, $db) or die(mysql_error($db));
}
?>
<p >Formulario de Compras</p>
<form method="post" action="<?php echo $php_self; ?>">
<table ><tr align="center">
</tr>
<tr align="center">
<td ><strong>Codigo</strong></td>
<td ><strong>Nombre</strong></td>
<td><strong> Fecha de Compra</strong></td>
<td ><strong>Precio Unitario</strong></td>
</tr>
<tr align="center">
<td width="128"><input name="codigo" type="text" id="codigo" size="15" maxlength="50"/></td>
<td > <input name="nombre" type="date" id="nombre" size="15" maxlength="50"/></td>
<td ><input name="fech_compra" type="text" id="fech_compra" size="15" maxlength="20"/></td>
<td ><input name="predcio" type="text" id="precio" size="15" maxlength="20"/></td>
<td ><input type="submit" name="btnGuardar" id="btnGuardar" value="Grabar" /></td>
</tr>
</table>
</form>
<?php
$sql_select = "SELECT * from compras";
$result = mysql_query($sql_select, $db) or die(mysql_error($db));
?>
<table >
<tr>
<th width="272" align="center">Codigo</th>
<th width="60" align="center">Nombre</th>
<th width="122" align="center">Fecha de Compra</th>
<th width="64" align="center">Precio </th>
</tr>
<?php
while ($row = mysql_fetch_array($result)) {
$codigo = $row['codigo'];
$nombre = $row['nombre'];
$fech_compra = $row['fech_compra'];
$precio = $row['precio'];
?>
<tr>
<td ><div><? echo $codigo; ?></div></td>
<td align="center" ><div ><? echo number_format($nombre,0,".","."); ?></div></td>
<td align="center"><div ><? echo $fech_compra; ?></div></td>
<td align="right" ><div><? echo number_format($precio,0,".","."); ?></div></td>
</tr>
<?
}
?>
</table> </body>
</html>