Form does not perform update

Asked

Viewed 71 times

-1

I created an editing form, where I put it on action the path to the update file and the Submit type button. But I click the button the page is not redirected and there is no update, there is nothing that is in the update file, below the update code, anyone who has suggestions of what is wrong thank.

<?php
$conexao = mysqli_connect('', '', '', ' ');
if(!$conexao){
    echo "<script> window.location.replace('../erro.html'); </script>"; 
} 
$id               = $_GET['id'];
$descricao        = $_POST['descricao'];

$sql  = "UPDATE nome_tabela1 SET descricao1 = '$descricao' where id = '$id'";

$sqlF = "UPDATE nome_tabela2 SET descricao2 = ''$descricao'' where id = '$id'";

$result         = mysqli_query($conexao, $sql); 
$result         = mysqli_query($conexao, $sqlF);

if ($result) {
    echo "<script> window.location.replace('../home.php'); </script>";
}else{
    echo "<script> window.location.replace('../erro.html'); </script>";     
}

mysqli_free_result($result);

Form:

    <?php
    $id = $_GET['id'];
    $conexao = mysqli_connect('', '', '', '');
    if(!$conexao){
        echo "<script> window.location.replace('../erro.html'); </script>"; 
    } 
    ?>
    <form class="form-horizontal tasi-form" method="POST" action="php/editar_contrato.php">
       <div class="form-group">
           <?php
              $result = mysqli_query($conexao, "SELECT * FROM tabela WHERE id = '$id'");
              while($exibe = mysqli_fetch_array($result)){?>
              <input type="hidden" name="id" value="<?php echo $exibe['id']?>"/>               
       </div>
       <div class="form-group">
            <label class="col-sm-2 col-sm-2 control-label">Descrição</label>
            <div class="col-sm-3">
                 <input type="text" class="form-control" name="descricao" required="required" value="<?php echo $exibe['cont_descricao'] ?>">
            </div>  
       </div>                                                                               
   </form>
    <?php
      }
    ?> 
   <div class="add-task-row">
        <input class="btn btn-success btn-sm pull-right" type="submit" value="Salvar" name="salvar">
        <span><p></p></span>
        <a href="contratos.php"><input class="btn btn-default btn-sm pull-right" type="reset" value="Cancelar" name="cancelar"></a>
   </div>
  • Can clarify further the "nothing happens"? It is not directed to the PHP page or is but updating in the database that is not effective?

  • Neither arrives on the page apparently, because the update does not occur and neither does the redirection to the successful page

  • Then possibly there is an error in your form. You have how to post the code?

1 answer

1


Assuming you have already verified that the page exists. The Submit button needs to be inside the form

  <?php
    $id = $_GET['id'];
    $conexao = mysqli_connect('', '', '', '');
    if(!$conexao){
        echo "<script> window.location.replace('../erro.html'); </script>"; 
    } 
    ?>
    <form class="form-horizontal tasi-form" method="POST" action="php/editar_contrato.php">
       <div class="form-group">
           <?php
              $result = mysqli_query($conexao, "SELECT * FROM tabela WHERE id = '$id'");
              while($exibe = mysqli_fetch_array($result)){?>
              <input type="hidden" name="id" value="<?php echo $exibe['id']?>"/>               
       </div>
       <div class="form-group">
            <label class="col-sm-2 col-sm-2 control-label">Descrição</label>
            <div class="col-sm-3">
                 <input type="text" class="form-control" name="descricao" required="required" value="<?php echo $exibe['cont_descricao'] ?>">
            </div>  
       </div> 
    <?php
      }
    ?> 
   <div class="add-task-row">
        <input class="btn btn-success btn-sm pull-right" type="submit" value="Salvar" name="salvar">
        <span><p></p></span>
        <a href="contratos.php"><input class="btn btn-default btn-sm pull-right" type="reset" value="Cancelar" name="cancelar"></a>
   </div>                                                                              
  </form>
  • I’ll adjust and test, thank you very much.

Browser other questions tagged

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