Programa llamado insert.html <HTML> <!-- comentarios --> <HEAD> <TITLE> datos generales </TITLE> </HEAD> <BODY> <center> <h2><i>registro de Producto</i></h2> <FORM Action="cgi-bin/insert.pl" METHOD=Post> <TABLE border=0> <TR > <TD> NUMERO DE IDENTIFICACION : </td> <TD Colspan=1> <input type=text name="id"> </td> <TR> <TD> NOMBRE :</td> <TD Colspan=2> <input type=text name="nombre"> </td> <TR> <TD> PRECIO :</td> <TD Colspan=3> <input type=text name="precio"> </td> <tdalign=center > <input type="submit" name=boton1 value="alta "> </td> </tr> </table> </form> </BODY> </HTML> Programa en perl llamado insert.pl #!/usr/bin/perl -w use strict; use CGI;
use DBI; my $q = new CGI; my $db="producto#maq"; my $tabla="articulos"; my $driver="mysql"; my $usuario="root"; my $id; my $nombre; my $precio; print $q->header("text/html"); print $q->start_html(-title =>"informacion"); print"\n"; $id =$q->param('id'); $nombre =$q->param('nombre'); $precio =$q->param('precio'); my $dbh=dbi->connect("dbi:$driver:$db",$usuario) die "\n error al abrir la base de datos"; my $resultado=$dbh->do ("insert into $tabla (id, nombre, precio) values ('$id', '$nombre','$precio');") warn "error al insertar datos"; print " <CENTER>\n"; print " <TABLE Border=1 >\n"; print " <TR ><TH colspan=2>datos </TH></TR>\n"; print " <TR ><Td> Nombre :</Td><td>$nombre</td></TR>\n"; print " <TR ><Td> id :</Td><td>$id</td></TR>\n"; print " <TR ><Td> precio :</td><td>$precio</td></tr>\n"; print " </TABLE>\n";
print " </CENTER>\n"; $dbh->disconnect warn "\fallo al desconectarse"; print $q->end_html(); Este programa es el código HTML que manda llamar a un CGI. Programa en llamado selectnombre.html
<HTML> <!-- comentarios --> <HEAD> <TITLE> datos generales </TITLE> </HEAD> <BODY> <center> <h2><i>registro de Producto</i></h2> <FORM Action="cgi-bin/selectnombre.pl" METHOD=Post> <TABLE border=0> <TR ><Td> Nombre : </td> </tr> </table> </form> </BODY> </HTML> <td Colspan=3> <input type=text name="nombre"></td> <tdalign=center > <input type="submit" name=boton1 value="busqueda "> </td> Programa en perl llamado selectnombre.pl #!/usr/bin/perl -w use strict; use CGI; use DBI; my $q = new CGI; my $db="producto#maq"; my $tabla="articulos";
my $driver="mysql"; my $usuario="root"; my $id; my $nombre; print $q->header("text/html"); print $q->start_html(-title =>"informacion"); print"\n"; $nombre =$q->param('nombre'); my $dbh=dbi->connect("dbi:$driver:$db",$usuario) die "\n erro al abrir la base de datos"; my $sth=$dbh->prepare ("select * from $tabla where nombre='$nombre'"); $sth->execute(); while (my $ref=$sth->fetchrow_hashref()){ $id=$ref->{id}; $nombre=$ref->{nombre}; print " <CENTER>\n"; print " <TABLE Border=1 >\n"; print " <TR ><TH colspan=2>datos </TH></TR>\n"; print " <TR ><Td> Nombre :</Td><td>$nombre</td></TR>\n"; print " <TR ><Td> id :</Td><td>$id </td></tr>\n"; print " </TABLE>\n"; print " </CENTER>\n"; } $sth->finish(); $dbh->disconnect warn "\fallo al desconectarse"; print $q->end_html();
Programa llamado delete.html <HTML> <!-- comentarios --> <HEAD> <TITLE> datos generales </TITLE> </HEAD> <BODY> <center> <h2><i>borar productos</i></h2> <FORM Action="cgi-bin/delete.pl" METHOD=Post>
<TABLE border=0> <TR> <TD> NUMERO DE IDENTIFICACION :</td> <TD Colspan=2> <input type=text name=id> </td> <tdalign=center > <input type="submit" name=boton1 value="borrar "> </td> </tr> </table> </form> </BODY> </HTML> Programa en perl llamado delete.pl #!/usr/bin/perl -w use strict; use cgi; use dbi; my $q = new cgi; my $db="producto#maq"; my $tabla="articulos"; my $driver="mysql"; my $usuario="root"; my $id; my $nombre; my $precio; print $q->header("text/html"); print $q->start_html(-title =>"informacion"); print"\n"; $id =$q->param('id');
my $dbh=dbi->connect("dbi:$driver:$db",$usuario) die "\n erro al abrir la base de datos"; my $sth=$dbh->prepare ("select * from $tabla where nombre='$id"); $sth->execute(); while (my $ref=$sth->fetchrow_hashref()){ $id1=$ref->{id}; $nombre=$ref->{nombre}; $precio=$ref->{precio}; print " <CENTER>\n"; print " <TABLE Border=1 >\n"; print " <TR ><TH colspan=2>datos </TH></TR>\n"; print " <TR ><Td> Nombre :</Td><td>$nombre</td></TR>\n"; print " <TR ><Td> id :</Td><td>$id </td></tr>\n"; print " </TABLE>\n"; print " </CENTER>\n"; if($id==$id1) { my $resultado=$dbh->do ("delete from $tabla where (id='$id');") warn "error al borrar datos datos"; } } $dbh->disconnect warn "\fallo al desconectarse"; print $q->end_html(); enlazando dos.pl <HTML> <!-- comentarios --> <HEAD>
<TITLE> datos generales </TITLE> </HEAD> <BODY> <center> <h2><i>datos a modificar</i></h2> <FORM Action="cgi-bin/modificar.pl" METHOD=Post> <TABLE border=0> <TR> <TD> NUMERO DE IDENTIFICACION :</td> <TD Colspan=2> <input type=text name=id> </td> <tdalign=center > <input type="submit" name=boton1 value="modificar "> </td> </tr> </table> </form> </BODY> </HTML> MODIFICAR #!/usr/bin/perl w use strict; use CGI; use DBI; my $q=new CGI; my $db= nombre base de datos ; my $tabla= nombre de la tabla ; my $driver= mysql ; my $usuario= nombre usuario ; my $pass= pasword ; my $nombre; my $precio;
print $q->header( text/htnl ); print $q=start_html(-title=> informacion ); print <center><br> MODIFICACIONES <br></center> ; my $id=$q->param(íd); my $dbh=dbi->connect( dbi:$driver:$bd:$host,$usuario,$pass) die \n eroro al abrir\n ; my $sth=$dbh->prepare( select * from $tabla where id= $id ); $sth->execute(); While (my $ref=$sth->fetchrow_hashref()) { $id=$ref->{id}; $nombre=$ref->{nombre}; $precio=$ref->{precio}; print <form action=modifica1.pl method=post> ; print <center> print <br>id :<input name=id value=$id><br> ; print <br>nombre :<input name=nombre value=$nombre><br> ; print </center> ; print <br> ; print <br> ; print <input type=submit name=boton1 value=modificar><br> ; print </form> ; } $sth->finish(); $dbh->disconnect; print $q->end_htlm(); + modificar1.pl
#!/usr/bin/perl w use strict; use CGI; use DBI; my $q=new CGI; my $db= nombre base de datos ; my $tabla= nombre de la tabla ; my $driver= mysql ; my $usuario= nombre usuario ; my $pass= pasword ; print $q->header( text/htnl ); print $q=start_html(-title=> informacion ); print <center><br> MODIFICACIONES <br></center> ; my $idprov=$q->param(íd); my $nombre=$q->param(nombre); my $dbh=dbi->connect( dbi:$driver:$bd:$host,$usuario,$pass) die \n eroro al abrir\n ; my $sth=$dbh->do( update from $tabla where id= $id nombre=$nombre ); print <center> print <br>id proveedor :<input name=id value=$id><br> ; print <br>nombre print </center> ; print <br> ; print <br> ; } $sth->finish(); $dbh->disconnect; print $q->end_htlm(); :<input name=nombre value=$nombre><br> ;