SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I use MYSQL function in a UPDATE statement?

    I was doing a test with mysql. this is the code

    PHP Code:
    update login set password=md5('aa'where login_id =1
    The question is, password does not take the md5 value of 'aa'.
    Possible to do it in 1 single SQL statement?

    I know in PHP I can store the md5 value in a variable before passing as password="{$stored_md5}". Just curious about SQL statement.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,328
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by resting View Post
    The question is, password does not take the md5 value of 'aa'.
    it doesn't?

    i got 4124bc0a9335c27f086f24ba207a4912 when i tested it

    what do you get?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    4124bc0a9335c27f086f24ba207a4912 same...

    weird..it works now...argh...but i'd already coded to store the md5 value in a variable first.

    thanks for the effort =)

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would encourage you to adhere to this format

    Code:
    UPDATE login SET password = MD5('aa') WHERE login_id =1;
    it makes it much easier to tell the difference between SQL functions/statements and fields/values
    Check out my web design blog.
    http://www.bolducpress.com


Bookmarks

Posting Permissions

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