www.webdeveloper.com
Results 1 to 3 of 3

Thread: MySQL Update Query Failing?

  1. #1
    Join Date
    Jan 2008
    Posts
    120

    MySQL Update Query Failing?

    Hello,

    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') {
                
    $ud_id=$_POST['ud_id'];
                            
    $new_title=$_POST['blog_title'];
                            
    $new_content=$_POST['blog_content'];
                            
    $postid=$_POST['postid'];
                            
    mysql_connect('*********',$username,$password);
                            
    $query="UPDATE blog SET title='$new_title', content='$new_content' WHERE id='$postid'";
                            print 
    $query;
                            
    mysql_query($query) or die("That didn't work at all.");
                            echo 
    "Table Updated";
                            
    mysql_close();
                            print 
    "<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:

    Code:
    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.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,633
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2008
    Posts
    120
    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!

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



Recent Articles