0

resulta que estoy ingresando datos a un sistema de información que estoy realizando. La idea es que me muestre los datos a través de un listado, sin embargo me arroja los siguientes errores:

Notice: Undefined index: id in C:\xampp\htdocs\Papeleria2\index.php on line 41 Notice: Undefined index: name in C:\xampp\htdocs\Papeleria2\index.php on line 42 Notice: Undefined index: cedula in C:\xampp\htdocs\Papeleria2\index.php on line 43 Notice: Undefined index: direccion in C:\xampp\htdocs\Papeleria2\index.php on line 44 Notice: Undefined index: telefono in C:\xampp\htdocs\Papeleria2\index.php on line 45 Notice: Undefined index: email in C:\xampp\htdocs\Papeleria2\index.php on line 46

Este es el código fuente para index.php

<?php
  require 'conexion.php';
  $sql = "SELECT * FROM clientes";
  $result = $mysqli->query($sql);
?>

<html>
<head>
  <title>Papelería</title>
</head>
</html>

<body>
  <div>
    <div>
      <h2 style="text-align:center">Papelería</h2>
    </div>

    <div class="row">
      <a href="NuevoCliente.php" class="button">Nuevo Registro</a>
    </div>

    <br>

    <div class="row table-responsive">
      <table>
        <thead>
          <tr>
            <th>Id</th>
            <th>Nombre</th>
            <th>Cedula</th>
            <th>Direccion</th>
            <th>Telefono</th>
            <th>Email</th>
          </tr>
        </thead>
        <tbody>
          <?php while($row = $result->fetch_array(MYSQLI_ASSOC))
          { ?>
            <tr>
              <td><?php echo $row['id']; ?></td>
              <td><?php echo $row['name']; ?></td>
              <td><?php echo $row['cedula']; ?></td>
              <td><?php echo $row['direccion']; ?></td>
              <td><?php echo $row['telefono']; ?></td>
              <td><?php echo $row['email'];?></td>
            </tr>
          <?php } ?>
        </tbody>
      </table>
    </div>
  </div>
</body>

Estoy a la espera de una posible solución al problema. Gracias.

2
  • Tiene toda la pinta de que o tu query falla o la tabla no tiene esos campos
    – JDev
    el 27 feb. 2019 a las 15:14
  • como estan definidos los cmapos en la BD? el 27 feb. 2019 a las 15:16

1 respuesta 1

0

Primero que nada verificar si tu consulta no está fallando haciendo un var_dump() y para imprimir tus datos en la tabla basta con hacer un foreach() y recorrer el array asociativo que obtuvimos utilizando mysqli_fetch_assoc().

Código:

<?php
  require 'conexion.php';
  $sql = "SELECT * FROM clientes";
  $result = $mysqli->query($sql);
?>
<html>
<head>
  <title>Papelería</title>
</head>
</html>
<body>
  <div>
    <div>
      <h2 style="text-align:center">Papelería</h2>
    </div>
    <div class="row">
      <a href="NuevoCliente.php" class="button">Nuevo Registro</a>
    </div><br>
    <div class="row table-responsive">
      <table>
        <thead>
          <tr>
            <th>Id</th>
            <th>Nombre</th>
            <th>Cedula</th>
            <th>Direccion</th>
            <th>Telefono</th>
            <th>Email</th>
          </tr>
        </thead>
        <tbody>
          <?php 
            $rows = $result->mysqli_fetch_assoc();
            foreach($rows as $row){ ?>
            <tr>
              <td><?php echo $row['id']; ?></td>
              <td><?php echo $row['name']; ?></td>
              <td><?php echo $row['cedula']; ?></td>
              <td><?php echo $row['direccion']; ?></td>
              <td><?php echo $row['telefono']; ?></td>
              <td><?php echo $row['email'];?></td>
            </tr>
          <?php } ?>
        </tbody>
      </table>
    </div>
  </div>
</body>

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.