0

I have a script which is supposed to delete a post from a database, however when the query is executed it does not delete anything. This is the query string.

$query = "DELETE post FROM kaoscraft_posts WHERE post_id = $postid"

What is wrong with the statement?

Yes, all variables are set and yes I have tested with an exact post_id

If you need more information, please just comment and tell me, don't be rude about it.

2
  • But being rude is what SO is best at! Commented Mar 9, 2014 at 17:00
  • @Strawberry Half the people that answer questions are rude. Commented Mar 9, 2014 at 17:12

4 Answers 4

5

From the MySQL manual:

For the single-table syntax, the DELETE statement deletes rows from tbl_name and returns a count of the number of deleted rows.

So you can't delete the post only, you need to delete whole row.

$query = "DELETE FROM kaoscraft_posts WHERE post_id = $postid"

If you want to clear the post only, you can do it by UPDATE statement.

Sign up to request clarification or add additional context in comments.

Comments

2

Delete query structure should be like this:

DELETE FROM table_name WHERE condition ;

You can not delete a column value in your table. you need to delete whole record of a row. If you wanted to delete single row then you need to update this row.

try this:

 $query = "DELETE  FROM kaoscraft_posts WHERE post_id = $postid";

Comments

1

You have an extra 'word' in your statement... it should be

$query = "DELETE FROM kaoscraft_posts WHERE post_id = $postid"

Comments

1

Please look on the below syntax,you come to know your mistake

DELETE FROM table_name WHERE column_name = some_value;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.