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. Link to comment https://forums.phpfreaks.com/topic/264008-mysql-query-help/ 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? Link to comment https://forums.phpfreaks.com/topic/264008-mysql-query-help/#findComment-1352990 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 Link to comment https://forums.phpfreaks.com/topic/264008-mysql-query-help/#findComment-1353007 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 .... Link to comment https://forums.phpfreaks.com/topic/264008-mysql-query-help/#findComment-1353015 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. Link to comment https://forums.phpfreaks.com/topic/264008-mysql-query-help/#findComment-1353150 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] Link to comment https://forums.phpfreaks.com/topic/264008-mysql-query-help/#findComment-1353154 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. Link to comment https://forums.phpfreaks.com/topic/264008-mysql-query-help/#findComment-1353155 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. Link to comment https://forums.phpfreaks.com/topic/264008-mysql-query-help/#findComment-1354465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.