Code to receive numeroCartao
of user via $_Session
and show all information about it. And from here I can delete this user via AJAX.
In this section of the code I can see the array containing all user data, however in the processaDadosExcluir.php
file I do not find the same array, which causes a undefined variable
error. And this prevents you from 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'];
}
?>