Jump to content

MySQL queries aren't doing anything


Recommended Posts

I'm developing a forum system in PHP, and so far everything's been going well, but I can't seem to get it to delete rows from multiple tables. The posts on the forum occupy 3 tables; one stores information such as who posted it when and what thread it's in, one stores the text, and one keeps track of any edits that are made to the post (who edited and when). These 3 tables are named, logically enough, posts, post_text and post_edits.

What I'm trying to do is delete all posts in a thread. To do this I need to delete all records in posts, post_text and post_edits that correspond to that thread. Only posts stores information about which thread the post is in, so based on the MySQL documentation (I'm stuck with V4.0 at the moment BTW), I came up with this:

"DELETE posts, post_text, post_edits FROM posts, post_text, post_edits WHERE posts.thread = $thread[id]"

This simply doesn't seem to do anything. It executes successfully but no rows are deleted from any table, even though the thread IDs match. :blink: Similarly, this query doesn't seem to do anything either:

"UPDATE forums SET views=views+$delforum[views], posts=posts+$delforum[posts], threads=threads+$delforum[threads] WHERE id=" . intval($moveto)

Even though the ID exists and the values being added are not zero; they remain unchanged. In the first query I suspect it may be because post_edits is empty (editing isn't implemented yet), but I can't figure this one out at all... Other queries made within the same function work fine.

Link to comment
Share on other sites


Have you tried enclosing the array called in the double-quotes with french braces?

Such as {$thread[id]} for example? From what I've experienced, double-quotes statements don't like calling array calls and instead call '$thread' and append '[id]' as plain text.

Additional note: Should enclose string variables in array brackets with single quotes. Notices will often popup saying that it will assume the string as a key instead. Using $thread['id'] will actually shut it up about it.

I have zero SQL experience myself as any databases I use are self-made\auto-maintained flat file databases. Only trying to do what i can... despite how little it is.

EDIT IN: Second thought - for the time being, have you tried deleting each entry individually rather than in multiples in one call? You claim it won't delete multiples so perhaps singles would be an effective workaround for now.

Edited by Chozo4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...