Jump to content

PHP Update Query not updating records properly


jcjst21

Recommended Posts

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");


}

 

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");

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");


}


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.