0% found this document useful (0 votes)
2 views3 pages

PHP Color Management System

The document connects to a MySQL database called 'colores' and performs read and write operations on a table called 'color' to get, display, and add color data. It includes PHP code to connect to the database, prepare and execute SQL statements to select, insert, and update color records in the table.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

PHP Color Management System

The document connects to a MySQL database called 'colores' and performs read and write operations on a table called 'color' to get, display, and add color data. It includes PHP code to connect to the database, prepare and execute SQL statements to select, insert, and update color records in the table.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<?

php

$servidor="localhost";
$bd="colores";
$usuario="root";
$clave="";

try{

    $conexion=new PDO("mysql:host=$servidor;dbname=$bd", $usuario,


$clave);
 

}catch(PDOExection){

echo "error";
}

<?php

include_once("[Link]");

//leer
$sql="SELECT * FROM `color`";
$include=$conexion->prepare($sql);
$include->execute();
$respuesta=$include->fetchAll();
//var_dump($respuesta);

//AGREGAR DATOS
if($_POST){

  $nombre=$_POST['name1'];
  $desceipcion=$_POST['name2'];

$sql2="INSERT INTO color (Nombre,Descripcion) values (?,?)";


$sentencia=$conexion->prepare($sql2);

$sentencia->execute(array($nombre ,$desceipcion));
header('location:[Link]');

}
?>

<!doctype html>
<html lang="es">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link
href="[Link]
.css" rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXupp
vnDJzQIu9" crossorigin="anonymous">
  </head>
  <body>
   
  <div class="container mt-5">
    <div class="row">
      <div class="col-md-6">

      <?php  foreach($respuesta as $dato):   ?>


      <div class="alert alert-<?php echo $dato["Nombre"] ?> text-
uppercase" role="alert">
            <?php echo $dato["Nombre"] ?>
            -
            <?php echo $dato["Descripcion"] ?>
       </div>
       <?php endforeach?>
      </div>

      <div class="col-md-5">  <strong>AGREGAR COLORES</strong>

    <form  method="POST">

     <br><input type="text" class="form_control" name="name1" id=""><br>


      <br><input type="text" class="form_control" name="name2" id=""><br>
      <button class="btn btn-success mt-5">enviar</button>

    </form>

    </div>
  </div>

    </div>

    </div>

  </div>
    <script
src="[Link]
[Link]" integrity="sha384-
HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm"
crossorigin="anonymous"></script>
  </body>
</html>

You might also like