Something is wrong with my update script

Discussion in 'PHP' started by Greenmethod, Aug 1, 2007.

  1. #1
    I'm not sure why its not updating, it is carrying the info over to the page, but its not changing the database info. Any ideas?

    mysql_query("UPDATE 'customer' SET 'Shop'=$Shop WHERE 'Cust_No'=$cust_no LIMIT 1");
    PHP:

     
    Greenmethod, Aug 1, 2007 IP
  2. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Can you put this after your code and tell us what the error is:

    echo mysql_error();
    PHP:
    Brew
     
    Brewster, Aug 1, 2007 IP
  3. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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 ''customer' SET 'Shop'=Village Coi WHERE 'Cust_No'=3783 LIMIT 1' at line 1

    Thanks for your help!
     
    Greenmethod, Aug 1, 2007 IP
  4. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yup...

    
    mysql_query("UPDATE 'customer' SET 'Shop'='$Shop' WHERE 'Cust_No'='$cust_no' LIMIT 1");
    
    Code (markup):
    notice the single quotes around $Shop and $cust_no?

    Incidentally, all your other single quotes are unnecessary.

    So you could just have....

    
    mysql_query("UPDATE customer SET Shop='$Shop' WHERE Cust_No='$cust_no' LIMIT 1");
    
    Code (markup):
    You only really need to single quote table names and columns if they happen to be reserved words.
     
    ecentricNick, Aug 1, 2007 IP
  5. DavidAusman

    DavidAusman Well-Known Member

    Messages:
    399
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Like mentioned earlier by Nick, you don't need to use single quote for the table name. If still no luck try
    mysql_query("UPDATE `customer` SET `Shop` = '$Shop' WHERE `Cust_No` = '$cust_no' LIMIT 1");
     
    DavidAusman, Aug 1, 2007 IP
  6. Sygon

    Sygon Peon

    Messages:
    439
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    
    
    mysql_query("UPDATE `customer` SET `Shop`='$Shop' WHERE `Cust_No`='".$cust_no."' LIMIT 1");
    
    
    PHP:
    Will work

    If not use:

    
    
    mysql_query("UPDATE `customer` SET `Shop`='$Shop' WHERE `Cust_No`='".$cust_no."' LIMIT 1") or die(mysql_error());
    
    
    PHP:
    and paste the error here;
     
    Sygon, Aug 1, 2007 IP