SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    syntax messed up

    Hey all.. havin a little battle with syntax errors maybe u can help me out
    PHP Code:
        $result=mysql_query("UPDATE users set $field='$value' where uid='$uid'")
            or die(
    mysql_error()); 
    it screws up at field. It is looking for the collom named $field instead of the collum named after the value stored in $field

    thanx for any help

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's odd. May I suggest that you place a whitespace before the = sign and see if that helps:

    "UPDATE*users*set*$field = '$value'*where*uid='$uid'"

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result=mysql_query("UPDATE users set $field = '$value' where uid='$uid'")
            or die(
    mysql_error()); 
    Unknown column '$field' in 'field list'



    whats that bit about field list?

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a reason why you have $field and not field? Is field supposed to be a variable?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Texas
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here the right code that should work

    PHP Code:
    $result=mysql_query("UPDATE TABLE users SET field='$value' WEHRE uid='$uid'")
            or die(
    mysql_error()); 
    I just woke up so if that don't work just say so and I'll look at it harder. Ya'll forgot TABLE after the UPDATE
    Mark -
    www.magicscripts.net

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by magicscripts
    here the right code that should work

    PHP Code:
    $result=mysql_query("UPDATE TABLE users SET field='$value' WEHRE uid='$uid'")
            or die(
    mysql_error()); 
    I just woke up so if that don't work just say so and I'll look at it harder. Ya'll forgot TABLE after the UPDATE
    Sorry that is just not true, you do not need to use TABLE in an update statement. Check the docs
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Texas
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ok. It's always worked for me and I've never learned different so. Thanks though. I love knowing something new.


    Whats up with all these php coding cats and perl coding cats? Man. I have 2 cats, their both lazy. I wish they'd at least learn html...
    Mark -
    www.magicscripts.net

  8. #8
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes.. field is a varibale
    and the variable is passed in the querystring. The variable should indicate which collum to update.

    so

    $field="name";
    $value="rob";
    $cid=3;

    update users set $field = '$value' where cid=$cid

    would read

    update users set name = 'rob' where cid=3

  9. #9
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result=mysql_query("UPDATE users set "$field ." ='$value' where uid='$uid'"
    It should be like that should it not?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


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
  •