Re: submitting records from multiple DB tables

From: Date: Tue, 31 Jul 2001 20:03:31 +0000
Subject: Re: submitting records from multiple DB tables
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-8598@lists.php.net to get a copy of this message
"Andrew.Martin" <Martin.Andrew@kpmg-ct.com> wrote in message news:94DEB1183C2ED4119E240090274D60FA83191A@exchange_dh.kpmg-ms.com... > I have a list of records displayed in a table generated from a DB > (records are from numerous DB tables). The table consits of check > box(name = DB name and index), title(url link with ID) date > and status Could you give a sample - the HTML code for one table row, with descriptive dummy values? > When the check box is selected I need to retrieve the DB > table name and a specific ID. The selected records are > then to be updated in the DB, but my problems arise > when trying to get the correct DB table name and ID. I see two ways of doing this; you can either return a parseable string from each checkbox, or you can return several associative arrays. Method #1: ========= in form file: <input type='checkbox' name='checkbox[]' value='$tablename;$id' > in recipient: <?php foreach ($checkbox as $val) { $res = explode(";", $val, 2); // table name = $res[0] // id = $res[1] } ?> Method #2 ======== in form file: <input type='checkbox' name='tbl[$num]' value='$tablename' > <input type='hidden' name='id[$num]' value='$id' > in recipient: <?php foreach($tbl as $key => $val) { // table name = $val // id = $id[$key] } ?> NOTE: both of these are quite insecure, letting any meddler specify whichever table id and row they want to play with, or maybe even execute arbitrary code of their own, depending on exactly how this is implemented; I strongly suggest using an associative array to filter the table names and forcing the id to an integer value. If you really want to be safe, you could generate a random key for each row of each table, pass it through a hidden field, and check it against the value again before changing the row. That way, whackers can only change rows that they have seen the 'password' for, which they would have the right to change anyway.

« previous php.windows (#8598) next »