RE: [PHP] Update Multiple Records From Form

2004-05-28 Thread Ford, Mike [LSS]
On 28 May 2004 04:47, Albert Padley wrote:

 I 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){
   $query = UPDATE ref_events_reg
SETfname = '$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?

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_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 Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Update Multiple Records From Form

2004-05-28 Thread Albert Padley
On May 28, 2004, at 3:50 AM, Ford, Mike [LSS] wrote:
On 28 May 2004 04:47, Albert Padley wrote:
I 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){
  $query = UPDATE ref_events_reg
 SETfname = '$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?
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_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,
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 Padley
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php