Skip to content

Instantly share code, notes, and snippets.

@silvarodrigo77
Created January 25, 2013 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save silvarodrigo77/4635771 to your computer and use it in GitHub Desktop.
Save silvarodrigo77/4635771 to your computer and use it in GitHub Desktop.
grava_la_dv.php
<?php
// Conecta ao MySQL usando MySQLi
$MySQLi = new mysqli("localhost", "root", "Digue2013", "alternativa");
// Recebe os dados do formulário
# $chNFe = $_GET['chNFe']; // Não é usado?
$identidade = $_POST['Id'];
$COD_BARRAS = $_POST['COD_BARRAS'];
$DT_LANCAMENTO = $_POST['DT_LANCAMENTO'];
$DT_DEVOLUCAO = $_POST['DT_DEVOLUCAO'] ;
// Prepara uma query
$query = $MySQLi->prepare("UPDATE `nfe_entrada` SET `COD_BARRAS` = ?, `DT_LANCAMENTO` = ?, `DT_DEVOLUCAO` = ? WHERE `Id` = ?");
$updates = 0;
foreach ($identidade AS $key => $id) {
$query->bind_param("sssd", $COD_BARRAS[$key], $DT_LANCAMENTO[$key], $DT_DEVOLUCAO[$key], (int)$id);
if ($query->execute()) {
$updates += (int)$MySQLi->affected_rows;
} else {
trigger_error($query->error);
}
$query->reset();
}
if ($updates > 0) {
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Lançamento e devolução salvos com sucesso!')
history.go(-1);
</SCRIPT>");
exit;
} else {
echo "<script>
alert('Não foi possível salvar lançamento e devolução!');
history.go(-1);
</script>";
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment