PHP Notice Code Error: Undefined variable: Connection in C: xampp htdocs admin Register.php on line 283

Asked

Viewed 143 times

-1

The following errors appear when opening the table page: Notice: Undefined variable: Connection in C: xampp htdocs admin Register.php on line 283

Warning: mysqli_query() expects Parameter 1 to be mysqli, null Given in C: xampp htdocs admin Register.php on line 283

Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, null Given in C: xampp htdocs admin Register.php on line 301

<div class="card-body">
              <div class="table-responsive">
              <?php

                  $query = "SELECT * FROM register";
                  $query_run = mysqli_query($connection, $query);

             ?>


                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                  <thead>
                    <tr>
                      <th>Nome</th>
                      <th>Protocolo</th>
                      <th>Data de abertura</th>
                      <th>Questionamento</th>
                      <th>Empresa</th>
                      <th>Observações</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
                    if(mysqli_num_rows($query_run) > 0)        
                    {
                        while($row = mysqli_fetch_assoc($query_run))
                        {
                  ?>
                      <td><?php  echo $row['nome']; ?></td>
                      <td><?php  echo $row['protocolo']; ?></td>
                      <td><?php  echo $row['data']; ?></td>
                      <td><?php  echo $row['questionamento']; ?></td>
                      <td><?php  echo $row['empresa']; ?></td>
                      <td><?php  echo $row['observacao']; ?></td>    

                      <?php } 
                        }
                        else {
                            echo "No Record Found";
                        }
                      ?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>

        </div>
        <!-- /.container-fluid -->
  • in the code shown does not actually have the $Connection variable, where it would be called?

  • In an external file connecting to the database.

1 answer

0

The following errors appear when opening the table page: Notice: Undefined variable: Connection in C: xampp htdocs admin Register.php on line 283

Connection data is missing from the $Connection variable passed as parameter in the mysqli_query function().

Try assigning the connection object before using the "$Connection variable".

Example:

$connection= mysqli_connect("localhost", "my_user", "my_password", "world");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.