Curso de PHP🐘 y MySql🐬 [50.- Editar registros parte 1🖊️]
En este tutorial vamos a editar los registros de nuestra tabla desde nuestra aplicacion, para ello vamos a crear un nuevo campo llamado acciones donde pondremos los iconos de editar y borrar (borrar aun no lo activaremos). Al hacer click en el boton editar nos enviara la formulario editar el cual cargara todos los datos de uestro registro para despues editar dichos datos.
Codigo: https://github.com/programadornovato/php/commit/d149d54397de5e9fec0bacc35c55b8bcd9823c62
< !-- Required meta tags -- >
< meta name= "viewport" content= "width=device-width, initial-scale=1, shrink-to-fit=no" >
< link rel= "stylesheet" href= "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity= "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin= "anonymous" >
< div class = "container mt-3" >
include_once "db_empresa.php" ;
$conexion = mysqli_connect ( $db_host, $db_user, $db_pass, $db_database ) ;
if ( $conexion == false ) {
echo "Error conexion" . mysqli_error ( $conexion ) ;
WHERE id='" . $_GET [ 'id' ] . "'
$resulSet = mysqli_query ( $conexion,$sql ) ;
$row= mysqli_fetch_array ( $resulSet,MYSQLI_ASSOC ) ;
< input type= "text" class = "form-control" name= "nombre" value= "<?php echo $row['nombre'] ?>" >
< label > Precio compra < /label >
< input type= "text" class = "form-control" name= "precioCompra" value= "<?php echo $row['precioCompra'] ?>" >
< label > Precio venta < /label >
< input type= "text" class = "form-control" name= "precioVenta" value= "<?php echo $row['precioVenta'] ?>" >
< label > Fecha compra < /label >
< input type= "text" class = "form-control" name= "fechaCompra" value= "<?php echo $row['fechaCompra'] ?>" >
< input type= "text" class = "form-control" name= "categoria" value= "<?php echo $row['categoria'] ?>" >
< label > Existencia < /label >
< input type= "text" class = "form-control" name= "unidadesEnExistencia" value= "<?php echo $row['unidadesEnExistencia'] ?>" >
< button type= "submit" name= "guardar" class = "btn btn-primary" > Guardar < /button >
< !-- Optional JavaScript -- >
< !-- jQuery first, then Popper. js , then Bootstrap JS -- >
< script src= "https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity= "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin= "anonymous" >< /script >
< script src= "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity= "sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin= "anonymous" >< /script >
< script src= "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity= "sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin= "anonymous" >< /script >
<!doctype html>
<html lang="en">
<head>
<title>Editar</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container mt-3">
<div class="row">
<div class="col-12">
<?php
include_once "db_empresa.php";
$conexion = mysqli_connect($db_host, $db_user, $db_pass, $db_database);
if ($conexion == false) {
echo "Error conexion" . mysqli_error($conexion);
}
$sql = "SELECT
`id`,
`nombre`,
`precioCompra`,
`precioVenta`,
`fechaCompra`,
`categoria`,
`unidadesEnExistencia`
FROM `productos`
WHERE id='" . $_GET['id'] . "'
;
";
$resulSet = mysqli_query($conexion,$sql);
$row=mysqli_fetch_array($resulSet,MYSQLI_ASSOC);
?>
<form>
<div class="form-group">
<label>Nombre</label>
<input type="text" class="form-control" name="nombre" value="<?php echo $row['nombre'] ?>">
</div>
<div class="form-group">
<label>Precio compra</label>
<input type="text" class="form-control" name="precioCompra" value="<?php echo $row['precioCompra'] ?>">
</div>
<div class="form-group">
<label>Precio venta</label>
<input type="text" class="form-control" name="precioVenta" value="<?php echo $row['precioVenta'] ?>">
</div>
<div class="form-group">
<label>Fecha compra</label>
<input type="text" class="form-control" name="fechaCompra" value="<?php echo $row['fechaCompra'] ?>">
</div>
<div class="form-group">
<label>Categoria</label>
<input type="text" class="form-control" name="categoria" value="<?php echo $row['categoria'] ?>">
</div>
<div class="form-group">
<label>Existencia</label>
<input type="text" class="form-control" name="unidadesEnExistencia" value="<?php echo $row['unidadesEnExistencia'] ?>">
</div>
<button type="submit" name="guardar" class="btn btn-primary">Guardar</button>
</form>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<title>Editar</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container mt-3">
<div class="row">
<div class="col-12">
<?php
include_once "db_empresa.php";
$conexion = mysqli_connect($db_host, $db_user, $db_pass, $db_database);
if ($conexion == false) {
echo "Error conexion" . mysqli_error($conexion);
}
$sql = "SELECT
`id`,
`nombre`,
`precioCompra`,
`precioVenta`,
`fechaCompra`,
`categoria`,
`unidadesEnExistencia`
FROM `productos`
WHERE id='" . $_GET['id'] . "'
;
";
$resulSet = mysqli_query($conexion,$sql);
$row=mysqli_fetch_array($resulSet,MYSQLI_ASSOC);
?>
<form>
<div class="form-group">
<label>Nombre</label>
<input type="text" class="form-control" name="nombre" value="<?php echo $row['nombre'] ?>">
</div>
<div class="form-group">
<label>Precio compra</label>
<input type="text" class="form-control" name="precioCompra" value="<?php echo $row['precioCompra'] ?>">
</div>
<div class="form-group">
<label>Precio venta</label>
<input type="text" class="form-control" name="precioVenta" value="<?php echo $row['precioVenta'] ?>">
</div>
<div class="form-group">
<label>Fecha compra</label>
<input type="text" class="form-control" name="fechaCompra" value="<?php echo $row['fechaCompra'] ?>">
</div>
<div class="form-group">
<label>Categoria</label>
<input type="text" class="form-control" name="categoria" value="<?php echo $row['categoria'] ?>">
</div>
<div class="form-group">
<label>Existencia</label>
<input type="text" class="form-control" name="unidadesEnExistencia" value="<?php echo $row['unidadesEnExistencia'] ?>">
</div>
<button type="submit" name="guardar" class="btn btn-primary">Guardar</button>
</form>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
VIDEO
🔗Iconos: https://fontawesome.com/ 🔗Bootstrap: https://getbootstrap.com
🎦Mysql configurar una replicación maestro – esclavo 🐬: https://www.youtube.com/watch?v=RY-EdBOJWEs
🎦 Esta lista de reproducción: https://www.youtube.com/playlist?list=PLCTD_CpMeEKS2Dvb-WNrAuDAXObB8GzJ0
Codigos en gdrive: https://drive.google.com/file/d/1tQwYvfL2jiUFc6beTWkOkGmXkq5zzFw2/view?usp=sharing Gracias por apoyar este canal: https://www.patreon.com/programadornovato?fan_landing=true
🔗 Facebook: https://facebook.com/ProgramadorNovatoOficial 🔗 Twitter: https://twitter.com/programadornova 🔗 Linkedin: https://www.linkedin.com/in/programadornovato/ 🔗 Instagram: https://www.instagram.com/programadornovato/