Fw: [PHP] Re: Scroll through values sent from a form

From: Date: Tue, 04 Mar 2003 19:26:50 +0000
Subject: Fw: [PHP] Re: Scroll through values sent from a form
Groups: php.general 
Request: Send a blank email to php-general+get-138157@lists.php.net to get a copy of this message
Invalid syntax. Replace '->' with '=>'. Also building arrays and using implode() is an alternative method to building the string.. foreach($_POST as $key => $val) { $fields[] = $key; $values[] = $val; } $fields = implode(', ', $fields); // collapse to string $values = implode(', ', $values); // collapse to string - Kevin ----- Original Message ----- From: "st" <shaun@mania.plus.com> To: <php-general@lists.php.net> Sent: Tuesday, March 04, 2003 12:19 PM Subject: [PHP] Re: Scroll through values sent from a form > thanks for your reply but it doesn't work, i get the following output: > > INSERT INTO Table (Object, Object, Object, Object, ) Values (, , , , ) > > any ideas? > > > "Bobby Patel" <anup_patel@rogers.com> wrote in message > news:20030304190848.26621.qmail@pb1.pair.com... > > $fields=''; > > $values=''; > > > > foreach ($_POST as $field -> $value) { > > $fields .= $field.", "; > > $values .=$value.", "; > > } > > $fields = substr ($fields, -2); // strip off last comma and space > > $values = substr ($values , -2); // strip off last comma and space > > > > $query = "INSERT INTO $_GET[table_name] (".$fields.") Values > (".$values.")"; > > > > > > "St" <shaun@mania.plus.com> wrote in message > > news:20030304185819.11944.qmail@pb1.pair.com... > > > Hi, > > > > > > Is it possible to scroll through values posted from a form using PHP? > Here > > > is my problem: I have a form on a page which is created dynamically from > > the > > > number of fields in a particular table, so when I POST the data how do I > > > create the INSERT statement? I feel this will be awkward due to the > > > construction of the INSERT statement and I would be very grateful for > > > anyone's input. The form names are the same as the field alues in the > > > table... > > > > > > It will need to be something like > > > > > > $query = " > > > > > > while (more Form Fields){ > > > $query = $query + "'form fieldname'"; > > > } > > > > > > $query = $query + ") VALUES ("; > > > > > > while (more POST Values){ > > > $query = $query + "POST Value"; > > > } > > > > > > $query = $query + ")"; > > > > > > I hope this makes sense to the reader! > > > > > > Thanks > > > > > > > > > > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#138157) next »