Home » Php » php – DELETE * FROM TABLE WHERE this=that not working

php – DELETE * FROM TABLE WHERE this=that not working

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

How to&Answers:

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

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

Answer:

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.

Answer:

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.