Jim Sundqvist Jim Sundqvist - 5 months ago 9
SQL Question

If statement not working after update query

I'm building a mail system, which have been great so far. However I'm stuck on the "delete mail" part.

In my database i have 2 columns (recdel and senddel) which responds to true or false.
Whenever a user press "delete" it updates the column to true based on sender or recipent and hides it from correct persons inbox.
When both the recipent and the sender have pressed delete i want to remove it from the database, unnecessary to have it there in case both parties have deleted it.

The issue stands when both parties have pressed delete, one of the parties must press delete once again for it to be deleted from the database (removed the hiding part for testing purposes).

The problem seems to be with the if statements, it wont go on to the third if statement after update query untill both colums are true, then it moves to the third if statement when delete is pressed for the third time.

I've also tried putting the third if statement inside the 2 first if statements, still having the same problem though.

Any thoughts?

if(person == sender) {
$query = 'UPDATE `email` SET `senddel`="true" WHERE `id`='.$id.'';
}

if(person == recipent) {
$query = 'UPDATE `email` SET `recdel`="true" WHERE `id`='.$id.'';
}

if(recdel == 'true' && senddel == 'true'){
delfromdb
}

Answer

Assigning to columns in the database doesn't automatically update PHP variables. You need to do another SQL query:

$query = 'DELETE FROM email WHERE recdel = "true" and senddel = "true" AND id = $id';