You are on page 1of 13

Index.

php

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Ejemplo de interaccion con DB</title>

<style type="text/css">

@import url("css/mycss.css");

</style>

<link href="css/bootstrap.css" rel="stylesheet" type="text/css">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->

<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->

<!--[if lt IE 9]>

<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>

<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

<![endif]-->

</head>

<body>

<div class="todo">

<div id="cabecera">

<img src="images/swirl.png" width="1188" id="img1">

</div>

<div id="contenido">

<table style="margin: auto; width: 800px; border-collapse: separate; border-spacing: 10px 5px;">

<thead>
<th>No.</th>

<th>ID</th>

<th>Producto</th>

<th>Descripcion</th>

<th> <a href="nuevo_prod1.php"> <button type="button" class="btn btn-


info">Nuevo</button> </a> </th>

</thead>

<?php

include "conexion.php";

$sentencia="SELECT * FROM productos";

$resultado=mysql_query($sentencia);

while($filas=mysql_fetch_assoc($resultado))

echo "<tr>";

echo "<td>"; echo $filas['no']; echo "</td>";

echo "<td>"; echo $filas['id_producto']; echo "</td>";

echo "<td>"; echo $filas['nombre']; echo "</td>";

echo "<td>"; echo $filas['descripcion']; echo "</td>";

echo "<td> <a href='modif_prod1.php?no=".$filas['no']."'> <button type='button' class='btn btn-


success'>Modificar</button> </a> </td>";

echo "<td> <a href='eliminar_prod.php?no=".$filas['no']."''><button type='button' class='btn btn-


danger'>Eliminar</button></a> </td>";

echo "</tr>";

?>

</table>

</div>
<div id="footer">

<img src="images/swirl2.png" id="img2">

</div>

</div>

</body>

</html>

Conexión.php
<?php

$conexion = mysql_connect("localhost","usuario","usuario");

mysql_select_db("mi_negocio",$conexion);

mysql_query("SET NAMES 'utf8'");

//date_default_timezone_set("America/Mexico");

/*

function limpiar($tags){

$tags = strip_tags($tags);

$tags = stripslashes($tags);

$tags = htmlentities($tags);

$tags = mysql_real_escape_string($tags);

return $tags;

*/

?>

Nuevo_prod1.php
<?php

include "conexion.php";

?>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Alta de Producto</title>

<style type="text/css">

@import url("css/mycss.css");

</style>

<link href="css/bootstrap.css" rel="stylesheet" type="text/css">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->

<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->

<!--[if lt IE 9]>

<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>

<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

<![endif]-->

</head>

<body>

<div class="todo">

<div id="cabecera">

<img src="images/swirl.png" width="1188" id="img1">

</div>

<div id="contenido">
<div style="margin: auto; width: 800px; border-collapse: separate; border-spacing: 10px 5px;">

<span> <h1>Alta de Nuevo Producto</h1> </span>

<br>

<form action="nuevo_prod2.php" method="POST" style="border-collapse: separate; border-spacing:


10px 5px;">

<label>Id Producto: </label>

<input type="text" id="id_producto" name="id_producto"><br>

<label>Producto: </label>

<input type="text" id="producto" name="producto" ><br>

<label>Descripcion: </label>

<textarea style="border-radius: 10px;" rows="3" cols="50" name="descripcion"


></textarea><br>

<br>

<button type="submit" class="btn btn-success">Guardar</button>

</form>

</div>

</div>

<div id="footer">

<img src="images/swirl2.png" id="img2">

</div>

</div>

</body>
</html>

Nuevo_prod2.php

<?php
include 'conexion.php';

NuevoProducto($_POST['id_producto'], $_POST['producto'], $_POST['descripcion']);

function NuevoProducto($id_prod, $nom, $descrip)

echo $sentencia="INSERT INTO productos (id_producto, nombre, descripcion) VALUES ('".


$id_prod."', '".$nom."', '".$descrip."')";

mysql_query($sentencia) or die (mysql_error());

?>

<script type="text/javascript">

alert("Producto Ingresado exitosamente");

window.location.href='index.php';

</script>

Modif_prod1.php

<?php
include 'conexion.php';

$consulta=ConsultarProducto($_GET['no']);

function ConsultarProducto($no_prod)

$sentencia="SELECT * FROM productos WHERE no='".$no_prod."' ";

$resultado=mysql_query($sentencia) or die (mysql_error());

$filas=mysql_fetch_assoc($resultado);

return [

$filas['id_producto'],

$filas['nombre'],

$filas['descripcion']

];

?>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Modificar Producto</title>

<style type="text/css">

@import url("css/mycss.css");

</style>

<link href="css/bootstrap.css" rel="stylesheet" type="text/css">


<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->

<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->

<!--[if lt IE 9]>

<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>

<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

<![endif]-->

</head>

<body>

<div class="todo">

<div id="cabecera">

<img src="images/swirl.png" width="1188" id="img1">

</div>

<div id="contenido">

<div style="margin: auto; width: 800px; border-collapse: separate; border-spacing: 10px 5px;">

<span> <h1>Modificar Producto</h1> </span>

<br>

<form action="modif_prod2.php" method="POST" style="border-collapse: separate; border-spacing:


10px 5px;">

<input type="hidden" name="no" value="<?php echo $_GET['no']?> ">

<label>Id Producto: </label>

<input type="text" id="id_producto" name="id_producto"; value="<?php echo $consulta[0] ?


>" ><br>

<label>Producto: </label>

<input type="text" id="producto" name="producto" value="<?php echo $consulta[1] ?>"><br>

<label>Descripcion: </label>
<textarea style="border-radius: 10px;" rows="3" cols="50" name="descripcion"> <?php echo
$consulta[2] ?> </textarea><br>

<br>

<button type="submit" class="btn btn-success">Guardar</button>

</form>

</div>

</div>

<div id="footer">

<img src="images/swirl2.png" id="img2">

</div>

</div>

</body>

</html>

Modif_prod2.php

<?php

include 'conexion.php';
ModificarProducto($_POST['id_producto'], $_POST['producto'], $_POST['descripcion'], $_POST['no']);

function ModificarProducto($id_prod, $nom, $descrip, $no)

$sentencia="UPDATE productos SET id_producto='".$id_prod."', nombre= '".$nom."',


descripcion='".$descrip."' WHERE no='".$no."' ";

mysql_query($sentencia) or die (mysql_error());

?>

<script type="text/javascript">

alert("Producto Modificado exitosamente");

window.location.href='index.php';

</script>

Eliminar_prod.php

<?php

include "conexion.php";
EliminarProducto($_GET['no']);

function EliminarProducto($no)

$sentencia="DELETE FROM productos WHERE no='".$no."' ";

mysql_query($sentencia) or die (mysql_error());

?>

<script type="text/javascript">

alert("Producto Eliminado exitosamente");

window.location.href='index.php';

</script>

You might also like