I'm pretty sure this is a very frequently asked question in this community but I haven't found a post that clarified my problem.
I have a table generated by a query,so I want to have a button ("x") to remove the row the button is positioned. My code so far obeys to the form method but won't delete the record.
this is my code:
<?php
include("includes/connect.php");
if(isset($_POST['procesar'])){
$fechaDesde = $_POST['fechaDesde'];
$fecha1 = date("Y-m-d", strtotime($fechaDesde));
$fechaHasta = $_POST['fechaHasta'];
$fecha2 = date("Y-m-d", strtotime($fechaHasta));
$params = [
[$fecha1, SQLSRV_PARAM_IN],
[$fecha2, SQLSRV_PARAM_IN],
];
$query ="{call mostrar_movimientos2(?,?)}";
$resultado = sqlsrv_query($con, $query, $params);
if ($resultado != false){
while ($row = sqlsrv_fetch_array($resultado, SQLSRV_FETCH_ASSOC)){
echo "<tr><th scope='row'><input class='form-control' name='idv' value='{$row['id']}' disabled></th>";
if ($row['concepto'] != 'Cheques'){
echo "<th scope='row'>$";
echo "{$row['importe']}</th>";
} else{
echo "<th scope='row'>-$";
echo "{$row['importe']}</th>";
}
echo "<th scope='row'>{$row['concepto']}</th>";
echo "<th scope='row'>{$row['fecha_movimiento']}</th>";
echo "<th scope='row'><button type='submit' name='borrar' class='btn btn-danger'>X</button></th></tr>";
}
} else{
echo('Algo salió mal: ');
print_r(sqlsrv_errors());
die();
}
if(isset($_POST['idv'])){
$id = $_GET['idv'];
$intid = (int)$id;
if(isset($_POST['borrar'])){
$queryd ="DELETE from movimientos where id = '$intid'";
$resultadod = sqlsrv_query($con, $queryd);
}
}}
?>