0
Hello, I have to develop a confirm button for deletion of a product. For this, I had the idea of running a file in php through ajax from the moment I click on "Confirm" in JS confirm, along, passing the value of a variable that will serve to make the sqls.
The problem is that I don’t know how to pass the value of this variable, we examples I found shows how to pass input values by id or values already determined, but nothing like what I need.
PHP with the JS:
<?php
$codprod = $_POST['produtoDelete'];// Esse é o valor que preciso para fazer as sqls
//JS
<script>
function excluirConfirm() {
var txt;
var r = confirm("Tem certeza que deseja excluir esse produto?");
if (r == true) {
//Aqui fica o ajax
$.ajax({
type: 'post',
url: 'produtoSessionEdit.php',
dataType: 'json',
data: {
codprod: ? //AQUI QUE ESTA MINHA DÚVIDA
} /* ... */
});
}else {
txt = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
?>
PHP file with sqls
<?php
ob_start();
session_start();
$codprod = $_POST['produtoDelete'];
//Deleção do produto
$select= "DELETE DESCRICAO FROM PRODUTO WHERE COD_PRODUTO=:codd";
$result= $pdo->prepare($select);
$result->bindParam(':codd', $codprod);
$result->execute();
echo '<script type="text/javascript"> alert("Produto excluido!"); </script>';
?>
What can I do to make this go away?
From what I understand you want to take this $codprod and send by ajax to the right php page?
– Anderson Henrique
Exactly. And also "call" the execution of the file, I believe I’m already doing it.
– Anderson Amorim