Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    48
    Thanks
    28
    Thanked 0 Times in 0 Posts

    mysql update fails

    Hi, The ref is populated from a form i.e,

    PHP Code:
    <?php echo $ref ?>
    This then updates a mysql table and I get the message 1 record updated, but it doesn't update. Any ideas on why it doesn't update the table.

    PHP Code:
    $sql="UPDATE table_one SET 
    ref='$ref',name='$name' WHERE ref ='$ref'"
    ;

    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    echo 
    "1 record updated";

    mysql_close($con)

    ?> 
    Not sure why it goes through but doesn't update..?

    Thanks in advance.
    Last edited by Inigoesdr; 12-26-2010 at 10:08 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by tau9 View Post
    Not sure why it goes through but doesn't update..?
    You aren't actually checking to see if it updated, only that the query was successfully executed. Check the number of affected rows with mysql_affected_rows() to see if it updated.

  • Users who have thanked Inigoesdr for this post:

    tau9 (12-27-2010)

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    48
    Thanks
    28
    Thanked 0 Times in 0 Posts
    I get the following reply when clicking submit.

    Updated records:-1

    I am assuming this is supposed to say 1 rather than -1.

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    48
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Sorry forgot to add the code, I used
    Code:
    PHP Code:
    ... .. .. printf ("Updated records:%d\n"mysql_affected_rows()); mysql_query("COMMIT"); 

  • #5
    New Coder
    Join Date
    Jan 2009
    Posts
    48
    Thanks
    28
    Thanked 0 Times in 0 Posts
    This has been resolved thanks for your help


  •  

    Posting Permissions

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