Está en la página 1de 13

Actualiza

<!DOCTYPE html>
<html>
<head>
<title>Ejemplo de PHP</title>
</head>
<body>
<?php
$id= $_GET['id'];
try {
require_once('conexion.php');
$sql="select * from tablacurso where id = $id";
$result=$conn->query($sql);
$datos = $result->fetch_assoc();
} catch (Exception $e) {
$error=$e->getMessage();
}
?>

<h1> Ejemplo de uso de bases de datos con PHP y MySQL</h1>

<FORM ACTION="modifica.php" method="get">


<TABLE>
<TR>
<TD>Nombre:</TD>
<TD><INPUT TYPE="text" NAME="nombre" SIZE="20" MAXLENGTH="30"
value="<?php echo $datos['nombre']; ?>"></TD>
</TR>

<TR>
<TD>Direccion:</TD>
<TD><INPUT TYPE="text" NAME="direccion" SIZE="20" MAXLENGTH="30"
value="<?php echo $datos['direccion']; ?>"></TD>
</TR>
<TR>
<TD>Telefono:</TD>
<TD><INPUT TYPE="text" NAME="telefono" SIZE="20" MAXLENGTH="30"
value="<?php echo $datos['telefono']; ?>"></TD>
</TR>

<TR>
<TD>Email:</TD>
<TD><INPUT TYPE="text" NAME="email" SIZE="20" MAXLENGTH="30" value="<?=
$datos['email']; ?>"></TD>
</TR>

<TR>
<TD>Imagen:</TD>
<TD><INPUT TYPE="text" NAME="imagen" SIZE="20" MAXLENGTH="30"
value="<?php echo $datos['imagen']; ?>"></TD>
</TR>
</TABLE>
<INPUT TYPE="submit" NAME="accion" VALUE="Modificar">
<input type="hidden" name="id" value="<?= $datos ['id']; ?>">
</FORM>
</body>
</html>
Agregar
<?php
$nombre=$_POST[nombre];
$direccion=$_POST[direccion];
$telefono=$_POST[telefono];
$email=$_POST[email];
$imagen=$_POST[imagen];
try {
require_once('conexion.php');
$sql="insert into tablacurso(nombre,direccion,telefono,email,imagen)
values('$nombre','$direccion', '$telefono', '$email', '$imagen')";
$result=$conn->query($sql);
} catch (Exception $e) {
$error=$e->getMessage();
}
header("Location: insertareg.php");
?>
Borra
<?php
$id= $_GET['id'];
try {
require_once('conexion.php');
$sql="delete from tablacurso where id = $id";
$result=$conn->query($sql);
} catch (Exception $e) {
$error=$e->getMessage();
}
header("Location: eliminareg.php");
?>
Busca

Buscareg
<html>
<head>
<title>Buscar registros BD.</title>
</head>
<body>
<H1>Buscar registros BD.</H1>
<?php
$dato = $_POST['nombre'];
try {
require_once('conexion.php');
$sql="select *from tablacurso where nombre like '%dato%'";
$result=$conn->query($sql);
} catch (Exception $e) {
$error=$e->getMessage();
}
printf("<h2><center>...Esta busqueda</h2></center><p>");
?>

<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>


<TR>
<TH>&nbsp;Nombre</TH>
<TH>&nbsp;Dirección&nbsp;</TH>
<TH>&nbsp;Telefono&nbsp;</TH>
<TH>&nbsp;Email&nbsp;</TH>
<TH>&nbsp;Imagen&nbsp;</TH>
</TR>
<form name="form1" method="post" action="modifica.php">
<?php
$i=0;
while($row = $result-> fetch_array())
{
printf("
<tr>
<td>&nbsp;%s</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td></td>
<td><a
href=\"actualiza.php?id=%d\">Modificar</a></td></tr>",$row["nombre"],$row["direccion"],$r
ow["telefono"],$row["email"],$row["imagen"],$row["id"]);

$i=$i+1;
}
$result->close();
$conn->close();

if($i==0)
{
printf("<p><center><h3>Datos no encontrados...</h3></center></p>");
}
printf("Datos encontrados...");
printf($i);
?>
</body>
</html>
Conexión
<?php
require_once (dbDetalles.php);
$conn= new mysqli($hostname, $username, $password, $database);
if ($conn->connect_error){
echo $error=$conn->connect_error;
exit();
}
?>
dbDetalles
<?php
$hostname="localhost";
$database="webapp26";
$username="webapp26";
$password="web26";
?>
Eliminareg
<?php
try {
require_once('conexion.php');
$sql="select *from tablacurso";
$result=$conn->query($sql);
} catch (Exception $e) {
$error=$e->getMessage();
}
?>

<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>


<TR>
<TH>&nbsp;Nombre</TH>
<TH>&nbsp;Dirección&nbsp;</TH>
<TH>&nbsp;Telefono&nbsp;</TH>
<TH>&nbsp;Email&nbsp;</TH>
<TH>&nbsp;Imagen&nbsp;</TH>
<TH>&nbsp;Borra&nbsp;</TH>
</TR>
<?php
while($row = $result-> fetch_array()) {
printf("
<tr>
<td>&nbsp;%s</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td></td>
<td><a
href=\"borra.php?id=%d\">Borra</a></td></tr>",$row["nombre"],$row["direccion"],$row["tel
efono"],$row["email"],$row["imagen"],$row["id"]);
}
$result->close();
$conn->close();
?>
Insertareg
<html>
<head>
<title>Ejemplo de PHP</title>
</head>
<body>
<H1>Ejemplo de uso de bases de datos con PHP y MySQL</H1>
<FORM ACTION="agregar.php" method="post">
<TABLE>
<TR>
<TD>Nombre:</TD>
<TD><INPUT TYPE="text" NAME="nombre" SIZE="20" MAXLENGTH="30"></TD>
</TR>

<TR>
<TD>Direccion:</TD>
<TD><INPUT TYPE="text" NAME="direccion" SIZE="20" MAXLENGTH="30"></TD>
</TR>

<TR>
<TD>Telefono:</TD>
<TD><INPUT TYPE="text" NAME="telefono" SIZE="20" MAXLENGTH="30"></TD>
</TR>

<TR>
<TD>Email:</TD>
<TD><INPUT TYPE="text" NAME="email" SIZE="20" MAXLENGTH="30"></TD>
</TR>

<TR>
<TD>Imagen:</TD>
<TD><INPUT TYPE="text" NAME="imagen" SIZE="20" MAXLENGTH="30"></TD>
</TR>
</TABLE>
<INPUT TYPE="submit" NAME="accion" VALUE="Grabar">
</FORM>
<hr>

<?php
try {
require_once('conexion.php');
$sql="select *from tablacurso";
$result=$conn->query($sql);
} catch (Exception $e) {
$error=$e->getMessage();
}
?>
<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>
<TR>
<TD>&nbsp;Nombre</TD>
<TD>&nbsp;Dirección&nbsp;</TD>
<TD>&nbsp;Telefono&nbsp;</TD>
<TD>&nbsp;Email&nbsp;</TD>
<TD>&nbsp;Imagen&nbsp;</TD>
</TR>
<?php
while($row = $result -> fetch_array()) {

printf("<tr><td>&nbsp;%s</td><td>&nbsp;%s&nbsp;</td><td>&nbsp;%s&nbsp;</td><td>&n
bsp;%s&nbsp;</td><td>&nbsp;<imgsrc=%s>&nbsp;</td></tr>",
$row["nombre"],$row["direccion"],$row["telefono"],$row["email"],$row["imagen"]);
}
$result->close();
$conn->close();
?>
</table>
</body>
</html>
Modifica
<?php
$id=$_GET[id];
$nombre=$_GET[nombre];
$direccion=$_GET[direccion];
$telefono=$_GET[telefono];
$email=$_GET[email];
$imagen=$_GET[imagen];
/* Para verificar si esta bien
$sql="UPDATE tablacurso SET
nombre='$nombre',direccion='$direccion',telefono='$telefono',email='$email',imagen='$imagen'
WHERE id='$id' ";
echo '$sql'*/

try {
require_once('conexion.php');
$sql="UPDATE tablacurso SET
nombre='$nombre',direccion='$direccion',telefono='$telefono',email='$email',imagen='$imagen'
WHERE id='$id' ";
$result=$conn->query($sql);
} catch (Exception $e) {
$error=$e->getMessage();
}
header("Location: modificareg.php");
?>
Modificareg
<html>
<head>
<title>Modificar registros BD.</title>
</head>
<body>
<H1>Modificar registros BD.</H1>
<?php
try {
require_once('conexion.php');
$sql="select *from tablacurso";
$result=$conn->query($sql);
} catch (Exception $e) {
$error=$e->getMessage();
}
?>

<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>


<TR>
<TH>&nbsp;Nombre</TH>
<TH>&nbsp;Dirección&nbsp;</TH>
<TH>&nbsp;Telefono&nbsp;</TH>
<TH>&nbsp;Email&nbsp;</TH>
<TH>&nbsp;Imagen&nbsp;</TH>
<TH>&nbsp;Modifica&nbsp;</TH>
</TR>
<?php
while($row = $result-> fetch_array()) {
printf("
<tr>
<td>&nbsp;%s</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td>
<td>&nbsp;%s&nbsp;</td></td>
<td><a
href=\"actualiza.php?id=%d\">Modificar</a></td></tr>",$row["nombre"],$row["direccion"],$r
ow["telefono"],$row["email"],$row["imagen"],$row["id"]);
}
$result->close();
$conn->close();
?>
</table>
</body>
</html>
SESIONES
Agregararticulo
<?php
session_start();
if( !isset( $_POST["clave"] ) ) {
?>
<body bgcolor="#D2EBF7" style="font-family: Tahoma;">
<?php echo "<h2>Usuario: " . $_SESSION["nombre"] . " " . $_SESSION["apellido"] . "</h2>";
?>
<form name="form1" method="post" action="agregararticulo.php">
<input type="hidden" name="clave" value="123456">
<table width="200">
<tr>
<td>Artículo</td>
<td><input type="text" name="articulo" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Cantidad</td>
<td><input type="text" name="cantidad" size="3" maxlength="3"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="Enviar">
</td>
</tr>
</table>
</form>
</body>
<?php
}
else {
$articulo = $_POST["articulo"];
$cantidad = $_POST["cantidad"];
$_SESSION["carrito"][$articulo] = $cantidad;
header( "location: carrito.php" );
}
?>
Carrito
<?php
session_start();
?>
<body bgcolor="#D2EBF7" style="font-family: Tahoma;">
<?php
echo "<h2>Usuario: " . $_SESSION["nombre"] . " " . $_SESSION["apellido"] . "</h2>";
if (count($_SESSION["carrito"]) == 0) {
echo "<h3>Carrito Vacio</h3>";
}
else {
echo "<table width='400' border='1'>";
foreach( $_SESSION["carrito"] as $articulo => $cantidad ) {
echo "<tr>";
echo "<td>$articulo</td>";
echo "<td>$cantidad</td>";
echo "</tr>";
}
echo "</table>";
}
?>
<a href="agregararticulo.php">Agregar Artículo</a>
<a href="cerrarsesion.php">Cerrar Sesión</a>
</body>
Cerrarsesion
<?php
session_start();
session_unset();
session_destroy();
header( "location: inicio.html" );
?>
Inicio
<html>
<head>
<title>Inicio de Sesión</title>
</head>
<body bgcolor="#D2EBF7" style="font-family: Tahoma;">
<h1>Inicio de Sesión</h1>
<form method="post" action="inicio.php" >
<table width="200">
<caption><strong>Ingrese sus Datos</strong></caption>
<tr>
<td>Nombre:</td>
<td><input type="text" name="nombre" size="15"
maxlength="15"></td>
</tr>
<tr>
<td>Apellido:</td>
<td><input type="text" name="apellido" size="15"
maxlength="15"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="submit" type="submit" value="Enviar">
</td>
</tr>
</table>
</form>
</body>
</html>

Iniciosesion
<?php
session_start();
if( !isset( $_POST["nombre"] ) or !isset( $_POST["apellido"] ) ) {
header( "location: inicio.html" );
}
else {
$_SESSION["nombre"] = $_POST["nombre"];
$_SESSION["apellido"] = $_POST["apellido"];
$_SESSION["carrito"] = array();
header( "location: carrito.php" );
}
?>

También podría gustarte