Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DELETE * FROM TABLE WHERE this=that not working

Tags:

php

select

mysql

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?

like image 326
Programmer Dude Avatar asked Apr 24 '16 04:04

Programmer Dude


2 Answers

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

"DELETE FROM users WHERE cookie='$cookie'"
like image 54
nhouser9 Avatar answered Oct 02 '22 00:10

nhouser9


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.

like image 32
Ike Wachuku Avatar answered Oct 02 '22 01:10

Ike Wachuku