jcjst21 Posted August 6, 2012 Share Posted August 6, 2012 Hi: My Update query below; is not updating either at ALL or it updates all records to the same number... Could someone please take a look and give me any suggestions? Thanks $select=mysql_query("SELECT campGroupAssignments.camperID, campGroupAssignments.campGroupID, CamperMedicationInfo.camperGroupID FROM campGroupAssignments LEFT JOIN CamperMedicationInfo ON campGroupAssignments.camperID=CamperMedicationInfo.camperID WHERE campGroupID=3"); while($result=mysql_fetch_array($select)) { $camper=$result['camperID']; $assignments=$result['campGroupID']; $needsSet=$result['camperGroupID']; echo $camper. " " .$assignments. " " .$needsSet. "</br>"; $update=mysql_query("UPDATE CamperMedicationInfo SET $needsSet=2 WHERE $assignments=2"); } Quote Link to comment https://forums.phpfreaks.com/topic/266733-php-update-query-not-updating-records-properly/ Share on other sites More sharing options...
Nyuszer Posted August 6, 2012 Share Posted August 6, 2012 you are trying to update columns that does not exist. $needsSet=$result['camperGroupID']; returns the value of camperGroupID from the current row. so your update query is something like this: UPDATE CamperMedicationInfo SET 3=2 WHERE 4=2 you have to use: $update=mysql_query("UPDATE CamperMedicationInfo SET camperGroupID=2 WHERE campGroupID=2"); Quote Link to comment https://forums.phpfreaks.com/topic/266733-php-update-query-not-updating-records-properly/#findComment-1367176 Share on other sites More sharing options...
jcjst21 Posted August 6, 2012 Author Share Posted August 6, 2012 I tried what you suggested and it changed everything to a 1... then I switched up the numbers to set it equal to something else and nothing was updated... here's my current code... //fix data $select=mysql_query("SELECT campGroupAssignments.camperID, campGroupAssignments.campGroupID, CamperMedicationInfo.camperGroupID FROM campGroupAssignments LEFT JOIN CamperMedicationInfo ON campGroupAssignments.camperID=CamperMedicationInfo.camperID WHERE campGroupID=2"); while($result=mysql_fetch_array($select)) { $update=mysql_query("UPDATE CamperMedicationInfo SET camperGroupID=2 WHERE campGroupID=2"); } Quote Link to comment https://forums.phpfreaks.com/topic/266733-php-update-query-not-updating-records-properly/#findComment-1367225 Share on other sites More sharing options...
btherl Posted August 6, 2012 Share Posted August 6, 2012 What are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/266733-php-update-query-not-updating-records-properly/#findComment-1367345 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.