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

Asked

Viewed 35 times

0

Aquivo php.

<?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>";
}
?>

Filing cabinet approve.php

<?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!";
  }
}

?>
  • The problem is here <input type='hidden' name='id' value='id'> <- the value is as id when it was supposed to be $row['id']

  • Could you tell me how to put it? the way I put it gave error in the syntax:c

  • Look at the answer I put.

  • 1

    worked perfectly, thank you @Noobsaibot for real! <3

1 answer

0


Not updating because you have set id as field value name="id" instead of $row['id'] in the archive php..

Alter:

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>";

for:

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>";

Browser other questions tagged

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