How to turn 2 forms into 1 only '

Asked

Viewed 23 times

0

Good morning, you guys, I have these two Forms that would be an input and an output, the two do Insert in the bank,:

<div class="col-md-6">
      <div class="panel panel-danger">
        <div class="panel-heading">ENTRADA</div>
          <div class="panel-body">
            <form class="form-horizontal" action="entrada.php" method="POST">
               <fieldset>
                 <div class="form-group">
                    <div class="col-md-12">
                    <input type="text" class="form-control" id="codigo" name="codigo" placeholder="CODIGO DO FUNCIONARIO">
                    </div>
                  </div>
                 <div class="form-group">
                    <center><button type="submit" class="btn btn-danger">ENTRAR</button></center>
                 </div>
               </fieldset>
           </form>
          </div>
        </div>
    </div>
    <div class="col-md-6">
      <div class="panel panel-danger">
        <div class="panel-heading">SAIDA</div>
          <div class="panel-body">
            <form class="form-horizontal" action="saida.php" method="POST">
               <fieldset>
                 <div class="form-group">
                    <div class="col-md-12">
                    <input type="text" class="form-control" id="codigo" name="codigo" placeholder="CODIGO DO FUNCIONARIO">
                    </div>
                  </div>
                 <div class="form-group">
                    <center><button type="submit" class="btn btn-danger">SAIR</button></center>
                 </div>
               </fieldset>
           </form>
          </div>
        </div>

What would be 1 so,in the bank I have employee status,when the input form makes an update on the status of it goes and it goes to 1 and when the output goes to 0.

I don’t know if I could express myself well,.

  • It does an update or does an Insert?

1 answer

1


If you use an employee-based UPDATE you can use this:

UPDATE tabela SET status = IF (`status`, 0, 1) WHERE funcionario = ?

This way it will invert between 0 and 1.

Example:

<form method="post">
<input type="text" name="funcionario">
<input type="submit">
</form>

<?php

if(isset($_POST['funcionario'])){

  $funcionario = $_POST['funcionario'];

  $update = $mysql->prepare("UPDATE tabela SET status = IF (`status`, 0, 1) WHERE funcionario = ?");

  $update->bind_param("s", $funcionario);
  $update->execute();

}

?>

Browser other questions tagged

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