0

I try to execute the following, what am I missing here ?

DELETE FROM escrow WHERE  host = '$name' OR challenger = '$name' AND id='$match_id'
1
  • Telling us what is happening vs what is expected would be a great start. We have no idea if the query runs but does not have the desired result, or if nearby kittens are catching on fire. Commented May 7, 2016 at 0:44

1 Answer 1

2

When you use AND and OR together in any circumstances in any programming language ALWAYS use brackets. There is an implicit order which gets evaluated first (the AND or the OR condition) but you usually don't know the order and shouldn't be in need to look it up in the manual

Also use Prepared statements for SQL queries which depends on variables.

In your case you either write

... WHERE (host = ? OR challenger = ?) AND id = ?

or

... WHERE host = ? OR (challenger = ? AND id = ?)

depending on what condition you want.

Also, when a SQL query fails for whatever reason check the error message you get from the database. It will tell you whats wrong with the query. However, a valid query which returns no rows (because the WHERE condition don't match for any row) is still a valid query and not an error, the result is just empty.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.