I do not know what the error of this code is, update button is not updating table field [closed]

0

<?php
include "mysqlexecuta.php"; // Executa a cláusula SQL

$servidor='localhost';
$banco='xerox';
$usuario='root';
$senha='';

$conexao = mysqli_connect($servidor,$usuario,$senha);
mysqli_select_db($conexao, $banco);

$sql = "SELECT id, id_usuario, data_req, tipo, quant, anexo, assunto,                         dataentrega, status FROM requisicao ORDER BY id ASC";
$result = mysqli_query($conexao,$sql) or trigger_error(mysqli_error($conexao));


echo "<table border='1'>

    <tr>
    <th>Número</th>
    <th>Requerente</th>
    <th>Data do Requerimento</th>
    <th>Tipo</th>
    <th>Quantidade</th>
    <th>Anexo</th>
    <th>Assunto</th>
    <th>Data de Entrega</th>
    <th>Status</th>
    <th>Aprovar </th>

</tr>";
while ($status = 'pendente') {

  while($row = mysqli_fetch_array($result))
  {
    echo "<tr>";
    echo "<th>" . $row['id'] . "</td>";
    echo "<th>" . $row['id_usuario'] . "</td>";
    echo "<th>" . $row['data_req'] . "</td>";
    echo "<th>" . $row['tipo'] . "</td>";
    echo "<th>" . $row['quant'] . "</td>";
    echo "<th>" . $row['anexo'] . "</td>";
    echo "<th>" . $row['assunto'] . "</td>";
    echo "<th>" . $row['dataentrega'] . "</td>";
    echo "<th>" . $row['status'] .  "</td>";
    echo "<th> <form method='POST' action='aprovar.php'>
   <input type='hidden' name='id' value='id'>
   <input type='submit' name='aprova' value='sim'>
    </form>
  </td>";

     echo "</tr>";
  }
  echo "</table>";
}
?>

Approve.php file

<?php

$servidor='localhost';
$banco='xerox';
$usuario='root';
$senha='';

$conexao = mysqli_connect($servidor,$usuario,$senha);
mysqli_select_db($conexao, $banco);

if(isset($_POST["aprova"])) {

  $sql = "UPDATE requisicao SET status='aprovado' WHERE  id='".$_POST["id"]."'";

  $query = mysqli_query($conexao, $sql);


  if($query) {

    echo "Sucesso!";
  }
  else {

    echo "Falha!";
  }
}

?>
    
asked by anonymous 18.06.2018 / 00:42

1 answer

0

You are not updating because you have set id as the value of the name="id" field instead of $row['id'] in the reqpendentes.php file.

Change:

echo "<td> <form method='POST' action='aprovar.php'>
      <input type='hidden' name='id' value='id'><!-- ERRO ESTA AQUI! -->
      <input type='submit' name='aprova' value='sim'>
    </form>
  </td>";

To:

echo "<td> <form method='POST' action='aprovar.php'>
      <input type='hidden' name='id' value='". $row['id'] ."'>
      <input type='submit' name='aprova' value='sim'>
    </form>
  </td>";
    
18.06.2018 / 01:30
Help in procedures triggers and basic SQL functions Create folder shortcut in C #