Is this possible "IF" statement

Wondering if this is possible, or should I do an additional select query before running this?

DELETE FROM 
    {$this->tblName}
    
WHERE 
    `id`='$id'
    
IF 
    (
    `assign_user` = '{$this->userID}'
    )
    
LIMIT 
    1


what are you doing? please explain

some of us don’t do php, and after all, you did post this question in the mysql forum

Hey, lol okay :stuck_out_tongue:

It was basically for a user permission, I popped 2 notes in here so it makes sense.


DELETE FROM
    notes   

WHERE
    -- First, Pick the Note to Delete
    `id` = '222'
   
IF
    (
    -- Then, Only delete the Note if the current selected Note
    -- Has this value, otherwise don't erase it
    
    `assign_user` = '13'
    )
   
   -- I only want to erase one at a time.
LIMIT
    1

What am I doing up at 5am lol. What is anyone doing up at 5am…

I bought a Rubix Cube btw, that thing is impossible to solve lol.

Here is how you would do it.


DELETE FROM
    notes   
WHERE
    id = 222
    AND assign_user = 13

You shouldn’t need the LIMIT when the id’s are unique.

what puzzles me is how you would allow some user who ~isn’t~ the assign_user to even get to the point in your app where they can request deletion of a note that isn’t theirs

but the AND is how you would do it

Hey thanks, I don’t know why I didn’t realize to use an AND statement.

For the most part someone can’t get to that section, but just to be double secure I want the query safe too. It’s a lot of working writing an application, I don’t think I realized what i was getting into :stuck_out_tongue:

haha