3
Guys, have a code in which I use the result of a SELECT to be a condition in the WHERE of a DELETE.
I’ll leave the code part to see if you can spot any errors. UPDATE (which is at the top of the code) works, but the DELETE part at the end is not working.
<?php
date_default_timezone_set('America/Sao_Paulo');
// CHAMANDO O ARQUIVO DE CONEXÃO AO BANCO
require_once("../conexao/conexao-com-banco.php");
//CONSULTA NO BANCO QUE MUDA O STATUS NO BANCO DE DADOS
session_start();
$usuario = $_SESSION["nome"];
//$estate = $_POST['estate'];
$tipo_atividade = $_POST['tipoatividade'];
$codi = $_POST['codigo'];
$cod = $_POST['cod'];
$data = date("Y-m-d H:i:s");
$inserirStandBy = "UPDATE tbl_atividades set CONFERENCIA = 'STANDY BY', DETALHES = CONCAT(IFNULL(DETALHES, 'Atualizações:'), 'ATIVIDADE PARA POR FALTA DE ARQUIVOS'), STATUS = 'STAND_BY', ATUALIZADO = 'S', DT_INICIO = NULL, DT_FIM = NULL WHERE codigo = $codi";
$resultado_update_stand = mysqli_query($conecta, $inserirStandBy);
$select_data = "SELECT DT_VENCIMENTO FROM tbl_atividades WHERE codigo = $codi";
$result_select_stand = mysqli_fetch_assoc(mysqli_query($conecta, $select_data));
$dt_vencimento = $result_select_stand['DT_VENCIMENTO'];
$deletar_atividades = "DELETE FROM tbl_atividades WHERE TIPO_ATIVIDADE = '$tipo_atividade' AND COD = '$cod' AND DT_VENCIMENTO > $dt_vencimento";
$result_delete_stand = mysqli_query($conecta, $deletar_atividades);
?>
NOTE: The result of SELECT is a DATE field.
I’m only posting the part of the code in PHP, I think it is not necessary the part of AJAX.
Thanks for your attention.
Have you tried to do a small test by manually printing the result of your variable that received SELECT and then trying to perform this delete manually to see if the problem is not in the value contained in the variable ?
– Nyelthon Refatti