bajsa

function pantalla($arr,$izq,$der)
{
printf(«<table>
<tr><td colspan=’2′>%s</td></tr>
<tr><td>%s</td><td>%s</td></tr>
</table>»,$arr,$izq,$der);
}
function formulario()
{
$sql=»select * from golosina order by nom»;

printf(«<html><head> <link rel=’stylesheet’ href=’hoja.css’ />»);
printf(«<title>Baja sencilla</title></head><body>»);

$con=mysql_connect(«localhost»,»root»,»»);
if (!$con) die(«Error conectando a MySQL»);
$base=mysql_select_db(«iw»);
if (!$base) die(«Error entrando en la BD»);
$res=mysql_query($sql);
//echo $sql;

$arr=»<img src=’banner.jpg’ alt=’banner’ />»;
$izq=»<a href=’http://www.cmaleon.es’>Ir al CMA</a><br />»;
$izq.=»<a href=’http://www.google.es’>Ir a GOOGLE</a><br />»;

$der=»<form name=’frm’ method=’post’ action=’baja.php’>»;
$der.=»Por favor, elija una golosina a eliminar…<hr />»;
$der.=»<select name=’codigo’>»;
while($fila=mysql_fetch_array($res))
{
$der.=sprintf(«<option value=’%d’>%s</option>»,$fila[«id»],$fila[«nom»]);
}
$der.=»</select>»;
$der.=sprintf(«<input type=’submit’ name=’ok’ value=’BORRAR’ />»);
$der.=»</form>»;

mysql_close($con);

pantalla($arr,$izq,$der);
printf(«</body></html>»);
}

function procesa()
{
$codigo=$_POST[«codigo»];
$sql=sprintf(«delete from golosina where id=%d»,$codigo);
//echo $sql;

$con=mysql_connect(«localhost»,»root»,»»);
if (!$con) die(«Error conectando a MySQL»);
$base=mysql_select_db(«iw»);
if (!$base) die(«Error entrando en la BD»);
$res=mysql_query($sql);

if (mysql_errno()==0) $der=»OK, todo fue bien<a href=’baja.php’>Otra vez</a>»;
else $der=»ERROR!!!»;

printf(«<html><head> <link rel=’stylesheet’ href=’hoja.css’ />»);
printf(«<title>Baja sencilla</title></head><body>»);
$arr=»<img src=’banner.jpg’ alt=’banner’ />»;
$izq=»<a href=’http://www.cmaleon.es’>Ir al CMA</a><br />»;
$izq.=»<a href=’http://www.google.es’>Ir a GOOGLE</a><br />»;
pantalla($arr,$izq,$der);
printf(«</body></html>»);
}
//si no necesito datos, el listado saldrá siempre igual
$haydatos=count($_POST);
if ($haydatos) procesa();
else formulario();
?>

Deja un comentario