DrTrans Posted June 11, 2012 Share Posted June 11, 2012 $propid = $_POST['propid']; $queryreg = mysql_query("UPDATE props SET (`address`,`city`,`state`,`zip`,`active`,`lease`,`leaseamt`,`deposit`,`latefee`,`managementfee`,`background`, `uselatefee`) VALUES ('$address','$city','$state','$zip','$active','$lease','$rent','$deposit','$latefee','$managementfee','$background','$usealatefee') WHERE propid = '$propid'" ) or die(mysql_error()); wondering why this query does not work. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 11, 2012 Share Posted June 11, 2012 What doesn't work about it? Any errors? Quote Link to comment Share on other sites More sharing options...
DrTrans Posted June 11, 2012 Author Share Posted June 11, 2012 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 '(`address`,`city`,`state`,`zip`,`active`,`lease`,`leaseamt`,`deposit`,`latefee`,' at line 2 Quote Link to comment Share on other sites More sharing options...
Barand Posted June 11, 2012 Share Posted June 11, 2012 You are using INSERT syntax. UPDATE syntax is UPDATE tablename SET field1 = value1, field2 = value2 ..... WHERE .... Quote Link to comment Share on other sites More sharing options...
DrTrans Posted June 12, 2012 Author Share Posted June 12, 2012 I understand that. but I'm updating multiple variables. Isn't there a much simpler way to do this. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 12, 2012 Share Posted June 12, 2012 The following is the UPDATE query syntax definition, with the most common usage shown in red - UPDATE [LOW_PRIORITY] [iGNORE] table_reference SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition] [ORDER BY ...] [LIMIT row_count] Quote Link to comment Share on other sites More sharing options...
Illusion Posted June 12, 2012 Share Posted June 12, 2012 I understand that. but I'm updating multiple variables. Isn't there a much simpler way to do this. Unfortunately not. A good practice may be inserting the record with a different version by having version column. if you are updating all the columns except id then actually you want to do a insert(assuming there are constraints in doing so ) and delete the old record. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 16, 2012 Share Posted June 16, 2012 Of course there's an easier way -- use a DB wrapper to write the queries for you, and pass it a hash. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.