mrpatg
mrpatg

Reputation: 10117

DELETE from mysql table WHERE column equals value AND column2 equals value2

Having some trouble getting this query to work correctly.

mysql_query("DELETE FROM `table` WHERE `id` = '$id' AND 'username' = '$username' ");

tried replacing variables with actual data and running it in phpmyadmin to no success

any thoughts?

Upvotes: 3

Views: 13161

Answers (2)

Paul Tarjan
Paul Tarjan

Reputation: 50642

Please, for the love of the internet, don't built an SQL query yourself. Use PDO.

Upvotes: 1

hobodave
hobodave

Reputation: 29303

You're quoting the username column with ' instead of `

use:

mysql_query("DELETE FROM `table` WHERE `id` = '$id' AND `username` = '$username'");

not:

mysql_query("DELETE FROM `table` WHERE `id` = '$id' AND 'username' = '$username'");

Upvotes: 17

Related Questions