Results 1 to 3 of 3

Thread: MySQL Update Query Failing?

  1. #1
    Join Date
    Jan 2008

    MySQL Update Query Failing?


    I'm trying to write a small snippet that does nothing but update a mysql table, but I'm having some trouble that has confounded me. I'm hoping that this is just one of those "I'm dumb for missing that" things, if anyone could help me I'd really appreciate it. Here's the code:

    PHP Code:
        if (isset($_GET['action'])) {
            if (
    $_GET['action']=='update') {
    $query="UPDATE blog SET title='$new_title', content='$new_content' WHERE id='$postid'";
    mysql_query($query) or die("That didn't work at all.");
    "Table Updated";
    "<script type='text/javascript' language='javascript'>window.location='index.php?suc=blu';</script>";
    To summarize it, the code is supposed to check if it's supposed to update, and if so, snag the content that was passed to it and replace it in the correct location in the table, which was also passed to it through the variable "postid". The code for opening the database is working, I'm using it many other places on the same site. From what I can determine, there's something wrong with my query, but I have no idea what. Here's all that pops up when I try to run this:

    UPDATE blog SET title='FJDSKLJFLKDSJFDKSLJFKLDS', content='The device has been modified.' WHERE id='2'That didn't work at all.
    The query prints as I think it should look, but I am new to mysql so I'm not sure.

    Any help at all or hint as to what I've done wrong would be appreciated greatly, thanks for your time.
    My code never has bugs. Just unintentional features.

  2. #2
    Join Date
    Aug 2004
    Try adding mysql_error() to the die() (instead of just the "didn't work" message) so that MySQL can tell you what it did not like about it.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Jan 2008
    Ahhh, thank you very much! I, er, didn't actually have a column labeled "id" in my database, thanks for helping me figure that out!
    My code never has bugs. Just unintentional features.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center