ngplayground
ngplayground

Reputation: 21627

PHP MYSQL DELETE FROM WHERE AND clause

Trying to get the following to work but for the life of me i cannot get this working.

Could someone assist?

DELETE FROM 'content' WHERE note_id = '7' AND WHERE userid = '1'
DELETE FROM 'note' WHERE id = '7' AND WHERE userid = '1'

I need to delete a record from each table where it checks that the user is actually that user but im getting syntax error when I run the query

I Receive the following when I remove the 2nd WHERE.

SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntac to user near 'DELETE FROM note WHERE id ='7' AND userid = '1" at line 2

Apologies turns out I added an extra space before the script got to here

Upvotes: 0

Views: 22018

Answers (5)

Deepak Singh
Deepak Singh

Reputation: 39

 DELETE FROM content WHERE note_id = '7' AND userid = '1'
 DELETE FROM note WHERE id = '7' AND userid = '1'

Try this there were two errors, ' with table and where clause written twice

Upvotes: 0

Only 1 WHERE needed, try this:

DELETE FROM content WHERE note_id = '7' AND userid = '1'
DELETE FROM note WHERE id = '7' AND userid = '1'

Upvotes: 9

Shail
Shail

Reputation: 1575

Use

DELETE FROM 'content' WHERE note_id = '7' AND userid = '1'
DELETE FROM 'note' WHERE id = '7' AND userid = '1'

Upvotes: 1

Fluffeh
Fluffeh

Reputation: 33522

You can't use single quotes around table names:

DELETE FROM `content` WHERE note_id = '7' AND userid = '1'

You have to use backticks around table and column names - not single quotes.

Also: You had two where in there - just use and between extra clauses.

Upvotes: 7

Vishal
Vishal

Reputation: 1234

You've added multiple WHERE clauses in a single query, which will not work.

Try this:

DELETE FROM content WHERE note_id = '7' AND userid = '1'

DELETE FROM note WHERE id = '7' AND userid = '1'

Upvotes: 3

Related Questions