1
I have a form already filled with two extra inputs only for the user to edit the information already registered and add the two new.
However, although the alert
of "successfully saved", when I consult the bank the information has not been changed nor the new added.
My form:
<?php
require 'strcon.php';
$query = mysqli_query($strcon, "SELECT SERVICO FROM pedidos");
$cliente = filter_input(INPUT_POST, 'CLIENTE');
$servico = filter_input(INPUT_POST, 'SERVICO');
$solicitacao = filter_input(INPUT_POST, 'SOLICITACAO');
$previsao = filter_input(INPUT_POST, 'PREVISAO');
$valor = filter_input(INPUT_POST, 'VALOR');
$acerto = filter_input(INPUT_POST, 'ACERTO');
$saldo = filter_input(INPUT_POST, 'SALDO');
$id = filter_input(INPUT_POST, 'ID');
?>
<!-- formulário -->
<form method="POST" action="update-edi.php">
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="form-group">
<label for="CLIENTE">Cliente:</label>
<input type="text" class="form-control" id="CLIENTE" name="CLIENTE" value="<?php echo $cliente; ?>">
</div>
<div class="form-group">
<label for="SERVICO">Serviço:</label>
<input type="text" class="form-control" id="SERVICO" name="SERVICO" value="<?php echo $servico; ?>">
</div>
<div class="form-group">
<label for="SOLICITACAO">Data de solicitação:</label>
<input type="text" class="form-control" id="SOLICITACAO" name="SOLICITACAO" value="<?php echo $solicitacao; ?>">
</div>
<div class="form-group">
<label for="PREVISAO">Data prevista:</label>
<input type="text" class="form-control" id="PREVISAO" name="PREVISAO" value="<?php echo $previsao; ?>">
</div>
<div class="form-group">
<label for="VALOR">Valor:</label>
<input type="text" class="form-control" id="VALOR" name="VALOR" value="<?php echo $valor; ?>">
</div>
<div class="form-group">
<label for="ACERTO">Acerto:</label>
<input type="text" class="form-control" id="ACERTO" name="ACERTO" value="<?php echo $acerto; ?>">
</div>
<div class="form-group">
<label for="SALDO">Saldo:</label>
<select type="text" class="form-control" id="SALDO" name="SALDO" value="<?php echo $saldo; ?>">
<option> Selecione... </option>
<option> Positivo </option>
<option> Negativo </option>
<option> Neutro </option>
</select>
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
</div>
</div>
</div>
</form>
My update page:
<?php
$acerto = filter_input(INPUT_POST, 'ACERTO');
$saldo = filter_input(INPUT_POST, 'SALDO');
$id = filter_input(INPUT_POST, 'ID');
$strcon = mysqli_connect('localhost', 'root', '', 'sis_tam') or die('Erro ao conectar ao banco de dados');
$sql = 'UPDATE pedidos SET ACERTO = " '. $acerto . ' ", SALDO = " '. $saldo . ' " WHERE ID = " '. $id . ' " ';
mysqli_query($strcon,$sql) or die("Erro ao tentar atualizar registro. " . mysqli_error($strcon));
mysqli_close($strcon);
echo '<script type="text/javascript">
alert("Salvo com Sucesso !");
window.history.go(-1);
</script>';
var_dump($acerto, $saldo, $id);
?>
I don’t understand why you’re not saving, if anyone understands, I thank you. :)
There is an extra space in the concatenation, what type of these fields?
– Roberto de Campos
The alert will always be triggered regardless of whether or not there was an update. Use the result of
mysqli_affected_rows($strcon)
to trigger the alert if yes. Learn more at http://php.net/manual/en/mysqli.affected-rows.php Already, the update problem seems to me that Roberto de Campos has already detected the error.– user60252
On the update page you are recovering an ID
$id = filter_input(INPUT_POST, 'ID');
not passed by the form.– user60252