<?php
$r = "../";
require_once($r."inc/funciones.php");
$mysqli = connectDB($r);

header('Content-Type: text/html; charset=utf-8');

$opts = '';
$sql = "SELECT id, categoria FROM z_categorias_productos ORDER BY categoria ASC";
if ($stmt = $mysqli->prepare($sql)) {
    $stmt->execute();
    $stmt->bind_result($id, $cat);
    while ($stmt->fetch()) {
        $id_s  = htmlspecialchars((string)$id, ENT_QUOTES, 'UTF-8');
        $cat_s = htmlspecialchars((string)$cat, ENT_QUOTES, 'UTF-8');
        $opts .= "<option value=\"{$id_s}\">{$cat_s}</option>";
    }
    $stmt->close();
}

echo '
<div class="form-group row">
  <label class="col-sm-3 col-form-label">Nombre Producto</label>
  <div class="col-sm-9">
    <input class="form-control" type="text" id="nameprod" name="nameprod" required autocomplete="off">
  </div>
</div>

<div class="form-group row">
  <label class="col-sm-3 col-form-label">Categoría</label>
  <div class="col-sm-9">
    <select class="form-control" id="categoriaprod" name="categoriaprod" required data-placeholder="Seleccione una categoría">
      <option value="">Seleccione una categoría</option>'
      . $opts .
    '</select>
  </div>
</div>
';

$mysqli->close();
