0
Code to receive the numeroCartao of the user via $_Session and show all information about it. And from here I can delete this user via AJAX.
In this excerpt of the code I can see the array containing all the user data, but in the file processaDadosExcluir.php cannot find the same array, which generates an error undefined variable. And this prevents running SQL.
How can I pass a variable to the file processaDadosExcluir.php so that it is recognized in this file in order to execute the query?
<?php ?>
<script type="text/javascript">
$('#excluirdep').submit(function(event) {
event.preventDefault();
var valores = $('#excluirdep').serialize();
console.log(valores);
$.ajax({
type: 'POST',
url: 'ajax/processaDadosExcluir.php',
data: valores,
dataType: 'html',
success: function (data) {
console.log(data);
$("#excluirDependente").html(data);
}
});
});
</script>
<?php
echo "Excluir pernamente o usuario: <br> Nome: ".$linha['NomeBeneficiario']."<br>
Numero da Carteira: ".$_SESSION ['NumeroCartao']."<br>";
/*variaveis de sessao*/
$numeroCartao = $_SESSION['NumeroCartao'];
//conexao
$con = mysql_connect("10.6.0.27","root","prtdb") or die("Erro na conexao!");
$db = mysql_select_db("teste001", $con) or die("Erro na selecao do banco");
//query
$sql = "DELETE FROM PlanAssiste WHERE NumeroCartao =".$numeroCartao;
//executar a query
$query = mysql_query($sql,$con) or die("Erro na Query-3: ".mysql_error());
//resposta
if ($query == NULL){
$return['msg'] = " <a href='#' class='close'>Fechar [X]</a> <br> <b> Nullo! </B>";
echo $return['msg'];
}
else{
$return['msg'] = "<div id='excluir' class='alter'>
<p><label> Excluido com Sucesso! </label> </p>
<p><a href='javascript:history.back(0)' >Fechar [X]</a> </p>
</div>
<style>
.alter{
width: 240px;
height: 200px;
color: red;
}
</style> ";
echo $return['msg'];
}
?>

What’s the name of the file you put on top?
– Sergio
After having edited, I’m under the impression that you put the code of your two files without any identification or separation when doing the copy/Paste (
arquivo1.php -> código+arquivo2.php -> código).– brasofilo
Exactly, there are two files...user.php and processDadosExcluir
– alexjosesilva