como puedo borrar y editar un registro que esta alojado en una bd pero que solo afecte a ese registro y no a los demas?
este es mi index.php
<?php
session_cache_limiter('nocache,private');
session_name('porcicola');
session_start();
if(empty($_SESSION["uid"]) || empty($_SESSION["pid"]) || empty($_SESSION["correo"]) || empty($_SESSION["usuario"]) || empty($_SESSION["perfil"])){
header('location:/');
}
?>
<?php
$html = "
<a href href= 'index.php?consultas=actualizar'>Actualizar<a/>
<a href href= 'index.php?consultas=eliminar'>Eliminar<a/>";
switch ($_GET)['consultas']){
case 'actualizar':
actualizar();
break ;
case 'eliminar':
actualizar();
break ;
default:
echo $ud;
}
function actualizar (){
$html= "<form method ='post' action = 'consultas.php?consulta=actualizar'>
ingresa id a actualizar: <input type ='text' name ='id'><br/>
ingresa nombre a actualizar <input type 'text' name= 'estado'><br/>
<input type = 'submit' value 'ok'>
a href href= 'index.php'>Regresar<a/>
</form>"
}
function eliminar (){
$html= "
<form method ='post' action = 'consultas.php?consulta=eliminar'>
ingresa id a eliminar: <input type ='text' name ='id'><br/>
<input type = 'submit' value 'ok'>
a href href= 'index.php'>Regresar<a/>
<form/>
"
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Registrar Estado</title>
<link href="../../css/estilos.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/png" href="../../images/favicon.png"/>
<link rel="shortcut icon" type="image/png" href="http://eg.com/favicon.png"/>
</head>
<body>
<div class="group">
<form action="registrarEstado.php" method="POST">
<input class="form-btn-menu" onClick="window.location.href='/app/'" name="menu" type="button" value="Menú" />
<input class="form-btn-cerrar" onClick="window.location.href='/'" name="cerrar" type="button" value="Cerrar Sesión" />
<br>
<center>
<h2><em>Registrar Estado</em></h2>
<label for="estado">Estado <span><em>(requerido)</em></span></label>
<input type="text" name="estado" class="form-input" required/>
</center>
<center>
<input class="form-btn" name="submit" type="submit" value="Registrar" />
<input class="form-btn" onClick="window.location.href='estados.php'" name="estados" type="button" value="Estados" />
</center>
</p>
</form>
</div>
</body>
</html>
donde hago los select para traer los datos que hay en la db
<?php
session_cache_limiter('nocache,private');
session_name('porcicola');
session_start();
if(empty($_SESSION["uid"]) || empty($_SESSION["pid"]) || empty($_SESSION["correo"]) || empty($_SESSION["usuario"]) || empty($_SESSION["perfil"])){
header('location:/');
}
require_once '../../clases/Conexion.php';
$cnx = new Conexion();
?>
<!doctype html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Estados</title>
<link href="../../css/estilos.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/png" href="../../images/favicon.png"/>
<!-- Bootstrap -->
<link href="/bootstrap/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/bootstrap/css/dataTables.bootstrap.min.css" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="/bootstrap/js/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="/bootstrap/js/jquery.dataTables.min.js"></script>
<script src="/bootstrap/js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#tabla').DataTable();
} );
</script>
</head>
<body>
<div class="divBooststrap">
<input class="form-btn-menu" onClick="window.location.href='/app/'" name="menu" type="button" value="Menú" />
<input class="form-btn-cerrar" onClick="window.location.href='/'" name="cerrar" type="button" value="Cerrar Sesión" />
<br>
<center><h2><em>LISTA DE ESTADOS</em></h2></center>
<div class="container">
<div class="table-responsive">
<table id="tabla" class="hover" width="100%">
<thead>
<tr>
<th class="col-md-2">ID</th>
<th class="col-md-10">ESTADO</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM estado ORDER BY estado";
$selectEstados = $cnx->ejecutarConsulta($sql, $cnx->consultar);
$selectEstados = $cnx->ejecutarConsulta($sql, $cnx->consultar);
if(!isset($selectEstados["msg"])){
$html = "";
foreach ($selectEstados as $key => $valor) {
$html.= "<tr>";
$html.= "<td>{$selectEstados[$key]["id_estado"]}</td>";
$html.= "<td>{$selectEstados[$key]["estado"]}</td>";
$html.= "</tr>";
}
echo $html;
}
else {
echo $selectEstados["msg"];
}
?>
</tbody>
</table>
</div>
</div>
<br>
<?php
if ($_SESSION["pid"]==="1") {
?>
<center>
<input class="form-btn" onClick="window.location.href='/app/estado/'" name="submit" type="button" value="Atrás"
/>
</center>
<?php
} else if ($_SESSION["pid"]==="2") {
?>
<center>
<input class="form-btn" onClick="window.location.href='/app/'" name="submit" type="button" value="Atrás" />
</center>
<?php
}
?>
</div>
<script type="text/javascript">
$('#tabla')
.removeClass( 'display' )
.addClass('table');
</script>
</body>
</html>
y donde hago el insert into
?php
session_cache_limiter('nocache,private');
session_name('porcicola');
session_start();
if(empty($_SESSION["uid"]) || empty($_SESSION["pid"]) || empty($_SESSION["correo"]) || empty($_SESSION["usuario"]) || empty($_SESSION["perfil"])){
header('location:/');
}
else {
require_once '../../clases/Conexion.php';
$cnx = new Conexion();
$estado = str_replace("'", "'", utf8_decode($_POST['estado']));
if(!empty($estado)){
$sql = "INSERT INTO estado (estado)
VALUES ('{$estado}')";
$insertEstado = $cnx->ejecutarConsulta($sql);
if ($insertEstado["estado"]) {
header('location:success.html');
} else {
header('location:fail.html');
}
}
else {
header('location:/app/estado/');
}
}
?>
espero un poco de su ayuda gracias