lunes, 1 de agosto de 2016

MODIFICAR UN REGISTRO

PRIMERO DEBEMOS DE TENER UN LINK EN EL FORMULARIO PRINCIPAL QUE NOS LLAME A ESTE ARCHIVO DE MODIFICAR....


<!DOCTYPE html>
<html>
<head>
<title>guardar</title>
</head>
<body>
<center>

<?php
$id=$_REQUEST['id'];
include("conexion.php");
$query="SELECT *FROM alumnos WHERE id='$id'";
$resultado=$conexion->query($query);
$row=$resultado->fetch_assoc();
?>
<form action="operacionmodificar.php?id=<?php echo $row['id'];?>" method="POST">
<CENTER><table border=2 width=400 align=center>
<tr>
<td>nombre</td>
<td> <input type="text" required name="nombre" size=44px placeholder="ingrese el nombre" value="<?php echo $row['nombre'];?>"/> </td>
</tr>
<tr>
<td>grado</td>
<td> <input type="text" required name="grado" placeholder="ingrese el grado academico" value="<?php echo $row['grado'];?>"/> </td>
</tr>
<tr>
<td>edad</td>
<td> <input type="text" required name="edad" placeholder="ingrese la edad de la persona" value="<?php echo $row['edad'];?>"/></td>
</tr>
<tr>
<td colspan=2 align="center">
<button type="submit">GUARDAR CAMBIOS</button>
</td>
</tr>
</table>
</FORM>
</CENTER>
</BODY>
</HTML>


__________________________________________________________________________________________________________________________________________________________________
LUEGO DEBEMOS DE CREAR UN ARCHIVO LLAMADO MODIFICAR.PHP
QUE ES EL QUE LLAMARA EL FORMULARIO ANTERIOR
<?php
include("conexion.php");
$id=$_REQUEST['id'];
$nombre= $_POST['nombre'];
$grado= $_POST['grado'];
$edad= $_POST['edad'];
$query="UPDATE alumnos SET nombre='$nombre', grado='$grado', edad='$edad' WHERE id='$id' ";
$resultado= $conexion->query($query);

if($resultado){
header("Location: tabla.php");
}
else
{
echo"error al insertar dato";
}
?>

COMO ELIMINAR UN REGISTRO

<?php
include("conexion.php");
$id=$_REQUEST['id'];
$query="DELETE FROM alumnos WHERE id='$id'";
$resultado=$conexion->query($query);
if($resultado){
header("Location: tabla.php");
}
else
{
echo"error al eliminar datos";
}


?>


DEBEMOS DE TOMAR EN CUENTA QUE EN NUESTRA TABLA PRINCIPAL
DEBE DE HABER UN LINK CON HREF QUE LLAME AL ARCHIVO DE ELIMINAR
SOLO DEBEMOS DE TOMAR EN CUENTA NUESTRAS VARIABLES...

FORMULARIO PARA CONSULTAR

<html>
<header>
<title></title>
<center><h1>CONSULTAR UN PRODUCTO</h1></select>
</header>
<body>
<center>
<form  method="post" action="consultar.php">

<label>INGRESE NOMBRE:</label>
<input type="text" name="producto">
<button type="submit" value="Aceptar">CONSULTAR</button>
</form>
</center>
</body>
</html>

LLAMAR UN FILA CON UN CRITERIO EN PHP

<!DOCTYPE html>
<html>
<head>
<title>guardar</title>
</head>
<body>
<center>

<?php
include("conexion.php");
$producto=$_POST['producto'];
$query="SELECT *FROM inventarios WHERE producto='$producto'";
$resultado=$conexion->query($query);
$row=$resultado->fetch_assoc();


?>

<CENTER><table border=2 width="200" align=center>
<tr>
<td>id</td>
<td> <input type="text"  name="id"  value="<?php echo $row['id'];?>"/> </td>
</tr>
<tr>
<td>producto</td>
<td> <input type="text" name="producto"  value="<?php echo $row['producto'];?>"/> </td>
</tr>
<tr>
<td>categoria</td>
<td> <input type="text"  name="categoria" value="<?php echo $row['categoria'];?>"/></td>
</tr>
<tr>
<td>fecha</td>
<td> <input type="date" name="fecha"  value="<?php echo $row['fecha'];?>"/></td>
</tr>
<tr>
<td>cantidad</td>
<td> <input type="text"  name="cantidad"  value="<?php echo $row['cantidad'];?>"/></td>
</tr>
<tr>
<td colspan=2 align="center">
<a href="index.html">INICIO</a>
</td>
</tr>
</table>

</CENTER>
</BODY>
</HTML>