RE: [PHP-DB] Question: Putting separate form elements into an array

From: Date: Sun, 17 Oct 2004 08:33:09 +0000
Subject: RE: [PHP-DB] Question: Putting separate form elements into an array
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-36866@lists.php.net to get a copy of this message
Not exactly sure what I did here. there are 5 skill textfields name skill[] then the years sky[] then the last used slu[] I was following the format of my other arrays, so stored them list this: if ( empty( $_SESSION['l_skill'] ) ) { $_SESSION['l_skill']=array(); } if ( is_array( $_REQUEST['skill'] ) ) { $_SESSION['l_skill'] = array_unique( array_merge( $_SESSION['l_skill'], $_REQUEST['skill'] ) ); } if ( empty( $_SESSION['l_years'] ) ) { $_SESSION['l_years']=array(); } if ( is_array( $_REQUEST['sky'] ) ) { $_SESSION['l_years'] = array_unique( array_merge( $_SESSION['l_years'], $_REQUEST['sky'] ) ); } if ( empty( $_SESSION['l_lastu'] ) ) { $_SESSION['l_lastu']=array(); } if ( is_array( $_REQUEST['slu'] ) ) { $_SESSION['l_lastu'] = array_unique( array_merge( $_SESSION['l_lastu'], $_REQUEST['slu'] ) ); } I think that is all fine, but I think at the critical moment (setup for database transaction is where my problem is and it's probably slight)Read past the code for my explanation. if ( is_array( $_SESSION['l_skill'] ) ) { foreach ( $_SESSION['l_skill'] as $s ) { } } if ( is_array( $_SESSION['l_years'] ) ) { foreach ( $_SESSION['l_years'] as $x ) { } } if ( is_array( $_SESSION['l_lastu'] ) ) { foreach ( $_SESSION['l_lastu'] as $z ) { } } $query = "INSERT INTO .............) VALUES ($...., '$s', $x, $z)"; At first I thought to nest all the "if ( is_array" but that produced some funky loop. So then I formatted as aboved. Problem is all i'm getting is the last element from each array into the database. I'm thinking then, perhaps not nested , but the if is arrays need to be formatted differently. Stuart --- Graham Cossey <graham@cossey.plus.com> wrote:

« previous php.db (#36866) next »