Re: Update Multiple Records From Form
| From: | Albert Padley | Date: | Fri, 28 May 2004 16:21:12 +0000 |
| Subject: | Re: Update Multiple Records From Form | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-187138@lists.php.net to get a copy of this message | ||
On May 28, 2004, at 3:50 AM, Ford, Mike [LSS] wrote:
On 28 May 2004 04:47, Albert Padley wrote:Thanks for the tweaks. That solved the problem. I had actually tried something like that, but obviously didn't have all the parts working together at the same time. Thanks again. Albert PadleyI feel I'm so close. I have a form with multiple database records with a checkbox to indicate which records to update set up like so: $name = "ed[" . $row['id'] . "]"; <input type=\"checkbox\" name=\"" . $name . "\" value=\"Y\"> Each text input is set up like so: <input type=\text\" name=\"fname[]\" value=\"" . $row['fname'] . "\"> On the processing page I am doing this: foreach($ed as $id=>$val){I'd make two tweaks, actually. First and most obviously, you're not selecting *which* fname field to pass to your update query, so this needs to be:$query = "UPDATE ref_events_regSET fname = '$fname' WHERE id = '{$id}'"; I am looping through the correct records, but every field is being updated to "Array". What tweak do I need to make?$query = "UPDATE ref_events_reg SET fname = '{$fname[$id]}' WHERE id = '{$id}'";(By putting just $fname there, you are telling PHP to insert the string representation of the whole array -- and the string representation of any array is, er, exactly "Array"! ;) This change may give you a clue to my other tweak -- I'd explicitly set the indexes of all the fname[] fields to be sure they sync correctly to the related check box, thus:<input type=\"checkbox\" name=\"ed[{$row['id']}]\" value=\"Y\"> <input type=\"text\" name=\"fname[{$row['id']}]\" value=\"{$row['fname']}\">Cheers! Mike Mike,