I have this problem: when I delete a course from a student I must also delete the outstanding payments of that course, those pending payments belong to a student. The problem is that I am erasing even the payments with condition of paid, and these I can not eliminate because I need them for income reports.
These are the tables from which I delete the data:
Of the inscribed table, I eliminate the inscription, and from the table payments_students I delete the rows where the payment status is equal to zero, that is, the pending payments. But it turns out that he is eliminating me until the payments with condition of paid.
If it is of importance, in the relation of the tables I have a DELETE ON CASCADE.
This is the function in which I do the DELETE:
function eliminando_curso_student()
{
$mysqli = new mysqli('localhost','root', '' , 'academia');
$id = $_GET['id'];
$query = "DELETE FROM inscritos WHERE id = '$id'";
$sql = $mysqli->query($query);
if($sql>0):
$query2 = "DELETE FROM pagos_estudiantes WHERE id_inscripcion = '$id' AND
estado = 0";
$sql2 = $mysqli->query($query2);
echo '<script type="text/javascript">javascript:history.back()</script>';
else:
echo mysqli_error($mysqli);
endif;
}
I deleted the registration of the course, but when it is going to delete the pending payments, it deletes even those that are in paid condition. Help please