0
I am trying to delete a record from my database after deleting physical file from a certain folder, physical file deletion occurs as expected but the one from the database fails, what I did was this:
if ($_POST["Operacao"] == 'ExcluirUpload') {
$sql = "SELECT * FROM gerDoctoContrato WHERE IdDocumento = ? AND IdContrato = ?";
if($stmt = $conn->prepare($sql) ){
$stmt->bind_param(
"ii",
$_POST["IdDocumento"],
$_POST["IdContrato"]
);
if ($stmt->execute()) {
$data = array();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$CaminhoAnexo = $row['CaminhoAnexo'];
$NomeArquivo = $row['NomeArquivo'];
unlink($CaminhoAnexo.$NomeArquivo);
}
$sqlUp = "DELETE FROM gerDoctoContrato WHERE IdDocumento = ? AND IdContrato = ?";
if($stmts = $conn->prepare($sqlUp) ){
$stmst->bind_param(
"ii",
$_POST["IdDocumento"],
$_POST["IdContrato"]
);
}
$aretorno["msg"] = "Registro excluído com sucesso.";
$aretorno["par"] = $_POST["IdContrato"];
} else {
$aretorno["msg"] = "Ocorreu um erro na exclusão dos dados: " . $stmt->error . ". Verifique.";
$aretorno["status"] = "ERRO";
}
} else {
$aretorno["msg"] = "Ocorreu um erro na preparação dos dados: " . $stmt->error . ". Verifique.";
$aretorno["status"] = "ERRO";
}
}
On my console appears this:
Uncaught TypeError: e.unbind is not a function
what error appears?
– pc_oc
It is used to be a referential integrity error, that is, this document is being linked in another table , its code is inside another table. Check if it is. If this is to solve you need to delete everything that has relation or null arrow in place to enable deletion.
– Renan Rodrigues
e.unbind is not a function
this looks like javascript error and not php error.– rray
I made a test commented the excerpt that should make the deletion and the script works, of course, not deleting the BD record.
– adventistapr
Which error appears? as it appears, the javascript event failed and does not call the php file to delete the record.
– rray