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


}

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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


}


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.