SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    panama
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help with UPDATE

    How do I update multiple fields in a row?. I have this

    $query = 'UPDATE productos SET nombre="'.$nombre.'", prod_code="'.$pcode.'", categoria="'.$categ.'", price="'.$precio.'" WHERE prod_no='.$mod;

    then sending it to $result = mysql_result($query,$connection)

    the thing is that I test that string and it just don't work what could be wrong.
    Last edited by arkngelus; Mar 2, 2005 at 23:00.

  2. #2
    SitePoint Zealot tcwatts's Avatar
    Join Date
    Jan 2003
    Location
    .my
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of $result = mysql_result($query,$connection), shouldn't it be

    $result = mysql_query($query,$connection)

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    panama
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, my mistake typing, but the $query string is OK??

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can I give you an advice? Nice-looking code is much easier to read and debug.

    PHP Code:
    $query "
        UPDATE productos SET 
            nombre     = '
    $nombre
            ,prod_code = '
    $pcode'
            ,categoria = '
    $categ'
            ,price     = '
    $precio'
        WHERE 
            prod_no = '
    $mod'
    "
    ); 

  5. #5
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you use mysql_error(); to spit out the error of the query, if any?

    Also, your using quotes around the $nombre variable (which I assume is number in greek or spanish). If this is an INT column then you need to remove the quotes. The same applies to $price. (and even $categories if this is a Foreign Key to a Catgeories table).

    Tryst

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    panama
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is what it is throwing
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

  7. #7
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like I said in my previous post, my sure you are not putting single quotes around values for columns who's DATA TYPES are INT.

    Tryst

  8. #8
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Pittsburgh PA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fyi tryst if i remember my high school spanish class... nombre is name ^_^
    Juggalo Forums ~ A true juggalo community come to life.
    TekBuzz ~ Under Construction
    Crystal Ball Developing ~ Under Construction

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,022
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    arkngelus, could you please echo the value of the query string just before you execute it

    p.s. i never took spanish ever, but i'm guessing nombre is number
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •