DELETE * FROM TABLE WHERE this=that not working

10,823

Solution 1

You don't need the * when using DELETE. Just do

"DELETE FROM users WHERE cookie='$cookie'"

Solution 2

When you use SELECT *, it works because you are selecting all columns from the table. In your case, your query should look like this

DELETE FROM users WHERE cookie='$cookie'

since the columns do not need to be specified here.

Solution 3

You can't have * in a DELETE statement.

If you want to delete all rows, this will do:

$query = mysqli_query($connection, "DELETE FROM users WHERE cookie='$cookie'");

When you use SELECT * FROM, * would select everything. However for DELETE, it isn't needed as you can only delete the whole row.

Share:
10,823
Programmer Dude
Author by

Programmer Dude

Updated on June 13, 2022

Comments

  • Programmer Dude
    Programmer Dude almost 2 years

    I'm not sure why this query isn't working! This query is to delete the user's account:

    $query = mysqli_query($connection, "DELETE * FROM users WHERE cookie='$cookie'");
    

    HOWEVER, when I replace DELETE with SELECT, it works! Is my DELETE syntax wrong?

  • Programmer Dude
    Programmer Dude about 8 years
    That was a really lazy mistake of me, thanks for that quick tip! ^_^
  • nhouser9
    nhouser9 about 8 years
    @ConnectionCoder No problem, happy to help! If this solved your problem, I'd really appreciate it if you accepted it as an answer.
  • Programmer Dude
    Programmer Dude about 8 years
    I'm about to do that, but the system won't allow me to accept an answer for another 8 minutes because of the really short amount of time I got an answer. I will accept the solution though!
  • nhouser9
    nhouser9 about 8 years
    @ConnectionCoder Thanks!