refiking Posted February 19, 2008 Share Posted February 19, 2008 I have 16 fields that I need to update and I'd like to do it with one query as opposed to 16 separate ones. When I tried this, it didn't work: $change = "UPDATE gatable SET (r1g1,r1g2,r1g3,r1g4,r1g5,r1g6,r1g7,r1g8,r1g9,r1g10,r1g11,r1g12,r1g13,r1g14,r1g15,r1g16) VALUES ('$r1g1','$r1g2','$r1g3','$r1g4','$r1g5','$r1g6','$r1g7','$r1g8','$r1g9','$r1g10','$r1g11','$r1g12','$r1g13','$r1g14','$r1g15','$r1g16')"; Link to comment https://forums.phpfreaks.com/topic/91948-updating-multiple-fields-in-a-db-with-one-query/ Share on other sites More sharing options...
pocobueno1388 Posted February 19, 2008 Share Posted February 19, 2008 Did you actually try to execute the query with mysql_query()? Try this: <?php $change = "UPDATE gatable SET (r1g1,r1g2,r1g3,r1g4,r1g5,r1g6,r1g7,r1g8,r1g9,r1g10,r1g11,r1g12,r1g13,r1g14,r1g15,r1g16) VALUES ('$r1g1','$r1g2','$r1g3','$r1g4','$r1g5','$r1g6','$r1g7','$r1g8','$r1g9','$r1g10','$r1g11','$r1g12','$r1g13','$r1g14','$r1g15','$r1g16')"; $result = mysql_query($change)or die(mysql_error() . "<p>With Query $change"); ?> Copy and paste the error if you get one. Link to comment https://forums.phpfreaks.com/topic/91948-updating-multiple-fields-in-a-db-with-one-query/#findComment-470861 Share on other sites More sharing options...
Chris92 Posted February 19, 2008 Share Posted February 19, 2008 No, the UPDATE works different to INSERT: $change = "UPDATE `gatable` SET `r1g1` = '$r1g1', `r1g2` = '$r1g2', `r1g3` = '$r1g3'"; and so on. Link to comment https://forums.phpfreaks.com/topic/91948-updating-multiple-fields-in-a-db-with-one-query/#findComment-470862 Share on other sites More sharing options...
refiking Posted February 19, 2008 Author Share Posted February 19, 2008 Ahh ok. Thanks! Link to comment https://forums.phpfreaks.com/topic/91948-updating-multiple-fields-in-a-db-with-one-query/#findComment-470870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.