I cannot resolve this error. Notice: Undefined variable: tree repor in C: e Notice: Undefined variable: valor_pagar in C:

Asked

Viewed 34 times

0

<?php
include("header.php");
include_once "Classe.php";
?>

<?php
$Ano = $_POST["Ano"];
$Estado = $_POST["Estado"];
$N_arvores_cortadas = $_POST["N_arvores_cortadas"];
$Volume = $_POST["Volume"];




$con = new mysqli("localhost","root",null,"calculo");

$con->query("INSERT INTO cal
 (Ano,Estado,N_arvores_cortadas,Volume,arvore_repor,valor_pagar) 
 VALUES ('$Ano','$Estado','$N_arvores_cortadas','$Volume','$arvore_repor','$valor_pagar')");

?>

<div class="alert alert-primary" role="alert">
  Gravado com Sucesso!
</div>


<a href="CalculadoraReflorestamento.php">Cadastrar</a>
<a align="left"><h3><font color='blue'>Valor R$ = 300</font></h3></a>
<table class="table">
  <thead class="thead-dark">
    <tr>
      <th scope="col">Ano</th>
      <th scope="col">Estado</th>
      <th scope="col">Nº arvores cortadas</th>
      <th scope="col">Volume(m³)</th>
      <th scope="col">Árvores a
Repor </th>

      <th scope="col">Valor a ser
pago </th>
    </tr>
  </thead>
  <tbody>
  <?php
  $con = new mysqli("localhost","root",null,"calculo");
  $r = $con->query("SELECT Ano,Estado,N_arvores_cortadas,Volume,arvore_repor,valor_pagar FROM cal");
  while ($l = $r->fetch_assoc()) {
echo "
<tr>
<th scope='row'><font color='white'><h3>$l[Ano]</h3></font></th>
<td ><font color='white'><h3>$l[Estado]</h3></font></td>
<td><font color='white'><h3>$l[N_arvores_cortadas]</h3></font></td>
<td><font color='white'><h3>$l[Volume]</h3></font></td>
<td><font color='white'><h3>$l[arvore_repor]</h3></font></td>
<td><font color='white'><h3>$l[valor_pagar]</h3></font></td>
</tr>

";
echo "$Estado";
  }
    ?>

  • 1

    Hello Hernandez, the problem is that the variables you are using in your query have not been declared.

  • where I must declare them?

1 answer

0

This error occurs because you missed checking your variable $tree:

$arvore_repor = isset($_POST["arvore_repor"]) ? ($_POST["arvore_repor"]) : '';

or you can simply use the function:

error_reporting(0);
  • Thank you very much!

  • @Hernandes - if you have supplied the need, please mark :D as the answer

Browser other questions tagged

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